feat(analytics): Add Swift Package Manager (SPM) support#235
feat(analytics): Add Swift Package Manager (SPM) support#235TheoGermain wants to merge 5 commits into
Conversation
|
Thanks for the detailed PR @TheoGermain, really appreciate the writeup and the verification checklist. I'll review and update here. |
|
Hi @TheoGermain, I tried running the example app with SPM enabled and the build is failing with the error below. Can you confirm if it works on your end? Thanks! |
|
Hi @ketanmixpanel, good catch — thank you for testing! The root cause is an SPM package identity mismatch. SPM derives a package's identity from the directory name for local path overrides. Flutter was pointing at the I just pushed a fix (aae8970) that makes three changes:
The |
|
@ketanmixpanel this needs to be merged on priority. |
|
@copilot resolve the merge conflicts in this pull request |
9f7dab6 to
dffb7d6
Compare
|
Merge conflicts resolved. The PR has been rebased on top of What changed in the rebase:
@ketanmixpanel — could you retest with the example app? |
Adds a Package.swift manifest for the iOS plugin so apps using Flutter's Swift Package Manager integration can resolve mixpanel_flutter natively instead of falling back to CocoaPods. CocoaPods consumers are unaffected. Changes: - ios/mixpanel_flutter/Package.swift: SPM manifest targeting iOS 12.0, depends on mixpanel-swift 6.4.0 (matches the podspec). - ios/mixpanel_flutter/Sources/mixpanel_flutter/: symlinks to swift/Classes/ (same pattern as macos/Classes/). - ios/mixpanel_flutter.podspec: source_files updated to Sources/ layout. - ios/Classes/: removed ObjC wrapper and old symlinks. The Swift class is now exposed to ObjC via @objc(MixpanelFlutterPlugin), making the wrapper redundant. - swift/Classes/SwiftMixpanelFlutterPlugin.swift: added @objc(MixpanelFlutterPlugin) so ObjC AppDelegate projects continue to work without the wrapper. Rebased on top of the packages/ monorepo restructuring (main after mixpanel#241). Closes mixpanel#176.
dffb7d6 to
1c45173
Compare
|
Any updates ? 😊 |
tylerjroach
left a comment
There was a problem hiding this comment.
One small comment. I believe the rest looks good. We will prioritize testing shortly. I promise it is on our radar.
| let package = Package( | ||
| name: "mixpanel_flutter", | ||
| platforms: [ | ||
| .iOS("12.0") |
There was a problem hiding this comment.
i had recently bumped to iOS 13 in a previous PR. Can we adjust this to 13?
There was a problem hiding this comment.
Done, bumped to 13.0 in bbaa0e1. This now matches the podspec and the example Podfile.
Closes #176.
Summary
Adds a
Package.swiftmanifest for the iOS plugin so apps using Flutter'sSwift Package Manager integration can resolve
mixpanel_flutternativelyinstead of falling back to CocoaPods. CocoaPods consumers are unaffected —
the
.podspecstill works and is unchanged in semantics.The scope of this PR is iOS only. macOS still uses CocoaPods; SPM support
for macOS can be added in a follow-up since it is largely the same pattern.
What changed
ios/mixpanel_flutter/Package.swiftmixpanel-swift6.3.0 (pinned to the same exact version as the podspec). iOS 12.0 minimum (matches the podspec).ios/mixpanel_flutter/Sources/mixpanel_flutter/swift/Classes/, mirroring the pattern already used bymacos/Classes/.ios/mixpanel_flutter.podspecsource_filesupdated to point at the newSources/directory.swift/Classes/SwiftMixpanelFlutterPlugin.swift@objc(MixpanelFlutterPlugin)to expose the Swift class to Obj-C registrants under the same name as the previous Obj-C wrapper. This preserves backwards compatibility for projects with an Obj-CAppDelegate.ios/Classes/.h/.m) is no longer needed since the Swift class is now@objc-exposed under the expected name. The old Swift symlinks here are replaced by the equivalent ones under the newSources/layout.Why eliminate the Obj-C wrapper
The previous
MixpanelFlutterPlugin.{h,m}only existed to bridge fromObj-C-named
MixpanelFlutterPlugin→ SwiftSwiftMixpanelFlutterPlugin.Mixed Swift+Obj-C SPM targets are awkward (SPM does not natively support
mixed-language targets in a single module).
By annotating the Swift class with
@objc(MixpanelFlutterPlugin):AppDelegate.mprojects) still find the class asMixpanelFlutterPlugin— no behavior change.This mirrors the approach already taken on macOS (where a Swift
typealiasserves the same purpose, no Obj-C wrapper).
Verification
flutter pub getsucceeds inexample/with SPM enabled(
flutter config --enable-swift-package-manager)flutter runbuilds and launches on an iOS simulator with SPM enabledflutter runbuilds and launches on an iOS simulator with SPM disabled(CocoaPods path)
pod lib lint ios/mixpanel_flutter.podspecstill passesAppDelegateconsumers still resolveMixpanelFlutterPluginvia the auto-generated registrant
Follow-ups (out of scope here)
macos/).match the existing podspec).
References
mixpanel-swiftalready supports SPM (Mixpanel/Package.swift)