-
Notifications
You must be signed in to change notification settings - Fork 59
Add Swift Package Manager (SPM) support for Flutter-SDK #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reshab-code
merged 25 commits into
feat/release_4.2.0
from
task/SDK-5694-spm-support-flutter-sdk
Sep 1, 2026
Merged
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b3d30e8
Create Package.swift file for spm support
reshab-code 2a7a415
Create symlinks for spm
reshab-code 5d96862
Add guard to obj c imports in ClevertapPlugin.m
reshab-code 203c1e3
wrapped both CTJsonTemplateProducer.h and CTCustomTemplatesManager.h …
reshab-code b91d176
Narrowed header files in podspec
reshab-code c0b7ecf
Relocate Package.swift to ios/clevertap_plugin/ for Flutter SPM detec…
reshab-code dfd2cf9
Add swift package name under ios in pubspec.yaml, added guards for th…
reshab-code 52d2d8e
Fix Package.swift to use same version as podspec to ensure no drift
reshab-code a7c16ee
Restructure folders and files as per the official flutter docs
reshab-code 8751ec8
Merge branch 'develop' into task/SDK-5694-spm-support-flutter-sdk
reshab-code 9e9fdf6
Fix version in package.swift to match podspec for correct version res…
reshab-code 74ecaa9
Add spm integration doc for flutter
reshab-code c22b0dc
Fix flutter version in pubspec to 1.1.7 and enable spm for supported …
reshab-code 8230f92
correct and trim the ios spm integration doc, fixing the enabling ste…
akashvercetti 8922ed1
ignore flutter ephemeral, local claude settings, and generated sdk re…
akashvercetti 7fa5ea4
Fix pr comments and add flutter framework dependency for swift pm rou…
reshab-code 25a953a
update integration doc for ct plugin v4.2.0 and core ios sdk verison …
reshab-code c021559
merge feat/release_4.2.0, resolve usnotifications import conflict in …
reshab-code da297b1
remove publicHeadersPath from Package.swift after docs review
reshab-code d6b8acb
port getAppLaunchNotification implementation to spm source path.
reshab-code 6589ae0
merge feat/release_4.2.0, bring in getAppLaunchNotification ios fix a…
reshab-code 5dd7d9f
remove flutterframework dependency from package.swift to support lowe…
reshab-code d65e9ac
add flutterframework warning to ios spm troubleshooting docs.
reshab-code 46f7bbf
port dismissPipInApp to spm source path.
reshab-code b423822
merge feat/release_4.2.0, resolve ios/Classes modify/delete conflict.
reshab-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| ## 📦 iOS Integration via Swift Package Manager (SPM) | ||
|
|
||
| Flutter introduced Swift Package Manager support as an **opt-in** feature in Flutter 3.24, and it became the **default** package manager in Flutter 3.44. The CleverTap Flutter plugin ships a `Package.swift` alongside its podspec, so both package managers resolve the same native SDK version (`CleverTap-iOS-SDK 7.7.1`). | ||
|
reshab-code marked this conversation as resolved.
Outdated
|
||
|
|
||
| > **Minimum requirements for SPM integration** | ||
| > - Flutter 3.24+ (opt-in) - enabled by default from Flutter 3.44 | ||
|
reshab-code marked this conversation as resolved.
|
||
| > - Xcode 15+ (required for `swift-tools-version: 5.9`) | ||
| > - iOS deployment target: 13.0+ | ||
| > | ||
| > If you are on Flutter < 3.24, the plugin continues to work via CocoaPods - no action required. | ||
|
|
||
| --- | ||
|
|
||
| ### How it works | ||
|
|
||
| The plugin ships a Swift package that pins `CleverTap-iOS-SDK 7.7.1`. When your app is built with SPM enabled, Flutter resolves it automatically - you don't add anything to your app's own `Package.swift` or edit any plugin files. | ||
|
|
||
| --- | ||
|
|
||
| ### Enabling SPM in your Flutter app | ||
|
|
||
| SPM is opt-in on Flutter 3.24–3.43 (and on by default from 3.44). There is **no** `flutter run`/`flutter build` flag and **no** `Info.plist` key for this - you enable it through Flutter configuration. | ||
|
|
||
| **Per project (recommended for testing)** - add to your app's `pubspec.yaml`: | ||
|
|
||
| ```yaml | ||
| flutter: | ||
| config: | ||
| enable-swift-package-manager: true | ||
| ``` | ||
|
|
||
| **Globally for your machine:** | ||
|
|
||
| ```bash | ||
| flutter config --enable-swift-package-manager | ||
| ``` | ||
|
|
||
| To turn it back off, use `enable-swift-package-manager: false` in `pubspec.yaml`, or `flutter config --no-enable-swift-package-manager` globally. | ||
|
|
||
| --- | ||
|
|
||
| ### Migrating an existing CocoaPods app to SPM | ||
|
|
||
| Once SPM is enabled, Flutter migrates the Xcode project automatically the next time you build or run. To migrate cleanly on an app that already uses CocoaPods: | ||
|
|
||
| **1. Enable SPM** (per-project block above, or global flag). | ||
|
|
||
| **2. Clear the existing CocoaPods state** (run from your app root): | ||
|
|
||
| ```bash | ||
| flutter clean | ||
| cd ios | ||
| rm -rf Pods Podfile.lock .symlinks build | ||
| rm -rf ~/Library/Developer/Xcode/DerivedData/Runner-* | ||
| cd .. | ||
| ``` | ||
|
|
||
| **3. Re-resolve and trigger the migration:** | ||
|
|
||
| ```bash | ||
| flutter pub get | ||
| flutter build ios --config-only # or: flutter run | ||
| ``` | ||
|
|
||
| On this build Flutter adds a `FlutterGeneratedPluginSwiftPackage` to the Xcode project and resolves every plugin that ships a `Package.swift` (including `clevertap_plugin`) via SPM. Plugins that only ship a podspec stay on CocoaPods - a hybrid setup is expected. | ||
|
|
||
| **4. Verify SPM took over.** Open `ios/Runner.xcworkspace` and confirm: | ||
| - **Package Dependencies** lists `clevertap_plugin` and, transitively, `clevertap-ios-sdk` at `7.7.1`. | ||
| - The regenerated `Podfile.lock` no longer contains a `clevertap_plugin` pod entry. | ||
|
|
||
| **5. Build and run** on a simulator/device and smoke-test CleverTap initialization plus a `recordEvent` to confirm native symbols link. | ||
|
|
||
| --- | ||
|
|
||
| ### AppDelegate changes when using SPM | ||
|
|
||
| When Flutter resolves the plugin via SPM, the module name changes. Use conditional imports in your `AppDelegate` to support both CocoaPods and SPM builds: | ||
|
|
||
| **Objective-C** | ||
|
|
||
| ```objc | ||
| #if __has_include(<CleverTapSDK/CleverTap.h>) | ||
| #import <CleverTapSDK/CleverTap.h> | ||
| #else | ||
| #import "CleverTap.h" | ||
| #endif | ||
|
|
||
| #if __has_include(<clevertap_plugin/CleverTapPlugin.h>) | ||
| #import <clevertap_plugin/CleverTapPlugin.h> | ||
| #else | ||
| #import "CleverTapPlugin.h" | ||
| #endif | ||
| ``` | ||
|
|
||
| **Swift** | ||
|
|
||
| ```swift | ||
| import CleverTapSDK | ||
| import clevertap_plugin | ||
| ``` | ||
|
|
||
| These guards ensure your app compiles correctly regardless of which package manager resolved the dependency. | ||
|
|
||
| --- | ||
|
|
||
| ### CocoaPods vs SPM | ||
|
|
||
| | | CocoaPods | SPM | | ||
| |---|---|---| | ||
| | SDK version pinned | `7.7.1` | `7.7.1` | | ||
| | Deployment target | `13.0` | `13.0` | | ||
|
reshab-code marked this conversation as resolved.
Outdated
|
||
| | Opt-in required | No | Yes on Flutter 3.24–3.43; default from 3.44 | | ||
|
|
||
| Both package managers resolve the same CleverTap iOS SDK version to ensure no drift between the two integration paths. | ||
|
|
||
| --- | ||
|
|
||
| ### Troubleshooting | ||
|
|
||
| - **Xcode doesn't resolve the package**: Run `flutter pub get`, then in Xcode go to **File → Packages → Resolve Package Versions**. | ||
| - **Automatic migration didn't add the package**: In Xcode, add it manually - **Package Dependencies → Add Local…** → select `ios/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage` and add it to the `Runner` target. Then under **Product → Scheme → Edit Scheme → Build → Pre-actions**, add a Run Script (with build settings from `Runner`): `"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" prepare`. | ||
|
reshab-code marked this conversation as resolved.
|
||
| - **Duplicate symbol errors**: Don't use both CocoaPods and SPM for the same plugin at once. If a `Podfile` exists and SPM is enabled, Flutter prefers SPM for plugins that support it. | ||
| - **Build fails with missing headers**: Verify your deployment target is `13.0` or higher in both your Xcode project and `Podfile`/`Package.swift`. | ||
|
reshab-code marked this conversation as resolved.
|
||
| - **Stale CocoaPods references after migrating**: If the build still runs `[CP]` Pods build phases (or duplicate-embeds a framework) for a plugin that has moved to SPM, run `pod deintegrate` in your app's `ios/` directory, then `flutter clean && flutter build ios` so Flutter re-integrates cleanly. Use this only as a recovery step - it is not part of the normal migration flow. Flutter regenerates the CocoaPods integration on every build, so a manual `pod deintegrate` is otherwise undone on the next build. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // swift-tools-version: 5.9 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "clevertap_plugin", | ||
| platforms: [ | ||
| .iOS("13.0") | ||
| ], | ||
| products: [ | ||
| .library(name: "clevertap-plugin", targets: ["clevertap_plugin"]) | ||
| ], | ||
| dependencies: [ | ||
| .package( | ||
| url: "https://github.com/CleverTap/clevertap-ios-sdk", | ||
| exact: "7.7.1" | ||
|
reshab-code marked this conversation as resolved.
Outdated
|
||
| ) | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "clevertap_plugin", | ||
| dependencies: [ | ||
| .product(name: "CleverTapSDK", package: "clevertap-ios-sdk") | ||
| ], | ||
| publicHeadersPath: "include/clevertap_plugin", | ||
|
reshab-code marked this conversation as resolved.
Outdated
reshab-code marked this conversation as resolved.
Outdated
|
||
| cSettings: [ | ||
| .headerSearchPath("include/clevertap_plugin") | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
80 changes: 80 additions & 0 deletions
80
ios/Classes/CleverTapPlugin.m → ...ources/clevertap_plugin/CleverTapPlugin.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.