Skip to content

feat(ios): add Swift Package Manager support#101

Open
ajaysubra wants to merge 5 commits into
masterfrom
ajaysubramanya/mage-699-support-swift-package-manager
Open

feat(ios): add Swift Package Manager support#101
ajaysubra wants to merge 5 commits into
masterfrom
ajaysubramanya/mage-699-support-swift-package-manager

Conversation

@ajaysubra
Copy link
Copy Markdown
Collaborator

@ajaysubra ajaysubra commented May 28, 2026

Summary

  • Adds ios/klaviyo_flutter_sdk/Package.swift so Flutter 3.44.0+ no longer warns that klaviyo_flutter_sdk lacks SPM support
  • Moves Swift source files from ios/Classes/ios/klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/ to match SPM's expected layout
  • Updates the podspec source_files path to the new location — CocoaPods remains fully functional

Closes #100 | Linear: MAGE-699

How it works

Flutter 3.44.0 introduced a warning (future error) for plugins without a Package.swift. The fix follows Flutter's guide for plugin authors: a Package.swift at ios/klaviyo_flutter_sdk/Package.swift declaring the Klaviyo Swift SDK dependencies.

Known limitation — local development

When developing this plugin locally with Flutter 3.44.0+ (where the repo is cloned as klaviyo-flutter-sdk), flutter build ios will hit an identity mismatch error. This is a Flutter tooling bug: Flutter derives the symlink name from the repo's directory basename (klaviyo-flutter-sdk with hyphens), but the SPM override identity uses the Dart package name (klaviyo_flutter_sdk with underscores). These are treated as different identities in Xcode 26's SwiftPM.

Workarounds for local dev:

  • Build via Xcode directly (CocoaPods path works fine)
  • Use Flutter < 3.44.0 (CI uses 3.38.7 and is unaffected)
  • Clone the repo into a directory named klaviyo_flutter_sdk

Not affected:

  • CI (uses Flutter 3.38.7 — CocoaPods only, Package.swift is ignored)
  • Pub.dev users with Flutter 3.44.0+ (pub-cache path has version suffix klaviyo_flutter_sdk-X.Y.Z, SwiftPM strips it → identity matches)

Known limitation — SPM dependency parity with the podspec

The podspec gates the optional native dependencies on environment variables, but Package.swift cannot express env-var-conditional dependencies, so they diverge:

Dependency podspec Package.swift
KlaviyoSwift always always
KlaviyoForms conditional (KLAVIYO_INCLUDE_FORMS, default on) always linked
KlaviyoLocation conditional (KLAVIYO_INCLUDE_LOCATION, default off) not declared

Consequences for consumers building through SPM (Flutter 3.44.0+ pub.dev users):

  • Cannot opt out of Forms via KLAVIYO_INCLUDE_FORMS=false
  • Geofencing (KlaviyoLocation) is unavailable — there is no SPM opt-in

CocoaPods consumers are unaffected. Tracking as a follow-up; SPM has no clean mechanism for build-time optional dependencies.

Test plan

  • Install the plugin from pub.dev with Flutter 3.44.0+ and verify flutter build ios produces no SPM warning for klaviyo_flutter_sdk
  • Verify flutter build ios still works with Flutter < 3.44.0 (CocoaPods path)
  • Verify pod install succeeds with the updated source_files path
  • Verify the example app builds and runs on device/simulator
  • Verify ./scripts/sync_version.sh updates the plist at its new path and verify-version-sync passes

🤖 Generated with Claude Code

ajaysubra and others added 3 commits March 23, 2026 11:27
Adds a Package.swift to ios/klaviyo_flutter_sdk/ so that Flutter 3.44.0+
does not warn that klaviyo_flutter_sdk lacks SPM support.

- Moves source files from ios/Classes/ to ios/klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/
  to conform to the SPM source layout expected by Flutter
- Adds Package.swift declaring KlaviyoSwift, KlaviyoForms, and KlaviyoLocation
  dependencies from klaviyo-swift-sdk ~> 5.3.1
- Updates podspec source_files path to match the new source location
  (CocoaPods path remains fully functional)

Note: when developing the plugin locally via a path dependency (repo
named klaviyo-flutter-sdk), flutter build ios with Flutter 3.44.0 will
hit an identity mismatch due to a Flutter tooling limitation with
hyphenated repo names. CI (Flutter 3.38.7) and pub.dev-installed users
are unaffected.

Closes #100

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread ios/klaviyo_flutter_sdk/Package.swift Outdated
Comment thread ios/klaviyo_flutter_sdk/Package.swift
@ajaysubra ajaysubra marked this pull request as ready for review May 28, 2026 15:42
@ajaysubra ajaysubra requested a review from a team as a code owner May 28, 2026 15:42
@klaviyoit klaviyoit requested a review from amber-klaviyo May 28, 2026 15:42
Copy link
Copy Markdown
Contributor

@ab1470 ab1470 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Bugbot's comments are valid

Comment thread ios/klaviyo_flutter_sdk/Package.swift Outdated
Comment thread ios/klaviyo_flutter_sdk/Package.swift
- Remove KlaviyoLocation from Package.swift dependencies — the source
  already guards all usage with #if canImport(KlaviyoLocation), so
  excluding it from SPM matches the podspec default (opt-in via
  KLAVIYO_INCLUDE_LOCATION=true) and avoids linking CoreLocation into
  every user's binary
- Move klaviyo-sdk-configuration.plist into the SPM source tree and
  declare it as a .process resource so the Klaviyo Swift SDK can read
  it at runtime for Flutter user-agent identification in SPM builds
- Update podspec resources path to match the new plist location

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 34d67f6. Configure here.

Comment thread ios/klaviyo_flutter_sdk.podspec Outdated
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.resources = ['klaviyo-sdk-configuration.plist']
s.source_files = 'klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/**/*'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md references outdated iOS source file path

Low Severity

The AGENTS.md architecture section still references ios/Classes/KlaviyoFlutterSdkPlugin.swift, but this PR moves Swift source files to ios/klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/. Since AGENTS.md serves as the authoritative project guide for AI agents and developers (per the AI Agent Guidelines rule), this stale path will misdirect anyone following it.

Fix in Cursor Fix in Web

Triggered by project rule: AI Agent Guidelines

Reviewed by Cursor Bugbot for commit 34d67f6. Configure here.

Comment thread ios/klaviyo_flutter_sdk.podspec Outdated
The SPM source move left three references pointing at the old
ios/Classes and ios/klaviyo-sdk-configuration.plist locations:

- podspec source_files globbed **/* which now matches the moved
  plist, double-including it (also in s.resources) and causing the
  Xcode "Unexpected duplicate tasks" build-ios failure. Scope to
  **/*.swift.
- .swiftlint.yml still `included: Classes` (now empty) -> SwiftLint
  "No lintable files found" lint failure. Point at the new Sources dir.
- sync_version.sh / bump_version.sh / version-check.yml still wrote
  and verified the old plist path, so version bumps would silently
  stop updating the shipped plist while version-check stayed green.
  Repoint all three at the moved plist.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ajaysubra ajaysubra requested a review from ab1470 May 29, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Swift Package Manager

2 participants