feat(ios): add Swift Package Manager support#101
Conversation
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>
ab1470
left a comment
There was a problem hiding this comment.
I think Bugbot's comments are valid
- 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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ 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.
| s.source = { :path => '.' } | ||
| s.source_files = 'Classes/**/*' | ||
| s.resources = ['klaviyo-sdk-configuration.plist'] | ||
| s.source_files = 'klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/**/*' |
There was a problem hiding this comment.
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.
Triggered by project rule: AI Agent Guidelines
Reviewed by Cursor Bugbot for commit 34d67f6. Configure here.
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>


Summary
ios/klaviyo_flutter_sdk/Package.swiftso Flutter 3.44.0+ no longer warns thatklaviyo_flutter_sdklacks SPM supportios/Classes/→ios/klaviyo_flutter_sdk/Sources/klaviyo_flutter_sdk/to match SPM's expected layoutsource_filespath to the new location — CocoaPods remains fully functionalCloses #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: aPackage.swiftatios/klaviyo_flutter_sdk/Package.swiftdeclaring 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 ioswill hit an identity mismatch error. This is a Flutter tooling bug: Flutter derives the symlink name from the repo's directory basename (klaviyo-flutter-sdkwith hyphens), but the SPM override identity uses the Dart package name (klaviyo_flutter_sdkwith underscores). These are treated as different identities in Xcode 26's SwiftPM.Workarounds for local dev:
klaviyo_flutter_sdkNot affected:
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.swiftcannot express env-var-conditional dependencies, so they diverge:KlaviyoSwiftKlaviyoFormsKLAVIYO_INCLUDE_FORMS, default on)KlaviyoLocationKLAVIYO_INCLUDE_LOCATION, default off)Consequences for consumers building through SPM (Flutter 3.44.0+ pub.dev users):
KLAVIYO_INCLUDE_FORMS=falseKlaviyoLocation) is unavailable — there is no SPM opt-inCocoaPods consumers are unaffected. Tracking as a follow-up; SPM has no clean mechanism for build-time optional dependencies.
Test plan
flutter build iosproduces no SPM warning forklaviyo_flutter_sdkflutter build iosstill works with Flutter < 3.44.0 (CocoaPods path)pod installsucceeds with the updatedsource_filespath./scripts/sync_version.shupdates the plist at its new path andverify-version-syncpasses🤖 Generated with Claude Code