Add Swift Package Manager (SPM) support for Flutter-SDK - #356
Add Swift Package Manager (SPM) support for Flutter-SDK#356reshab-code wants to merge 18 commits into
Conversation
…imports with guards
…tion with a Classes symlink
…e clevertap.h and clevertapPlugin.h in AppDelegate, remove locale parameter from StyledToast causing build failure
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds Swift Package Manager support for the CleverTap Flutter iOS plugin. It defines the package manifest, updates CocoaPods and Flutter metadata, adds conditional Objective-C imports, changes custom template registration to accept an explicit bundle, and documents setup and migration procedures. ChangesSwift Package Manager Integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant FlutterProject
participant SwiftPackageManager
participant CleverTapPlugin
participant CleverTapSDK
FlutterProject->>SwiftPackageManager: Resolve clevertap_plugin
SwiftPackageManager->>CleverTapSDK: Resolve exact 7.7.1
SwiftPackageManager-->>CleverTapPlugin: Provide package headers and sources
CleverTapPlugin->>CleverTapSDK: Import available SDK headers
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ios/clevertap_plugin.podspec`:
- Around line 14-17: The podspec currently pins the CleverTap iOS SDK exactly
(s.dependency 'CleverTap-iOS-SDK', '7.6.0') while Package.swift uses SwiftPM's
from: "7.6.0" range; update the version policy so both package managers
match—either change the podspec dependency to a matching range (e.g., '>= 7.6.0'
or a compatible '~> 7.6.0') to mirror SwiftPM's semantics, or change
Package.swift to pin exactly "7.6.0"; modify the s.dependency line in
ios/clevertap_plugin.podspec or the Package.swift from: entry accordingly so
both use the same constraint.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 377d95db-be1e-42e3-b694-a2d8e0a43aed
📒 Files selected for processing (12)
example/ios/Runner/AppDelegate.mexample/lib/main.dartios/Classes/CleverTapPlugin.mios/Classes/CleverTapPluginCustomTemplates.mios/Classes/include/CleverTapPlugin.hios/Classes/include/CleverTapPluginAppFunctionPresenter.hios/Classes/include/CleverTapPluginCustomTemplates.hios/Classes/include/CleverTapPluginTemplatePresenter.hios/clevertap_plugin.podspecios/clevertap_plugin/Classesios/clevertap_plugin/Package.swiftpubspec.yaml
💤 Files with no reviewable changes (1)
- example/lib/main.dart
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@reshab-code https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors, check for this official docs if our changes follows folder and files structures and names |
# Conflicts: # ios/clevertap_plugin.podspec
|
@coedrabbitai review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@doc/Integrate-iOS-SPM.md`:
- Line 60: The Markdown headings for the Objective-C and Swift sections are
skipping levels, which breaks the document hierarchy. Update the section
headings identified by Objective-C and Swift to use a consistent intermediate
heading level so they follow the prior subsections instead of jumping from h3 to
h6. This should be applied to both occurrences mentioned in the diff to satisfy
linting and keep the structure readable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 25d4ee61-a799-4855-a661-995eefb1b010
📒 Files selected for processing (13)
doc/Integrate-iOS-SPM.mdios/.gitignoreios/clevertap_plugin.podspecios/clevertap_plugin/Package.swiftios/clevertap_plugin/Sources/clevertap_plugin/CleverTapPlugin.mios/clevertap_plugin/Sources/clevertap_plugin/CleverTapPluginAppFunctionPresenter.mios/clevertap_plugin/Sources/clevertap_plugin/CleverTapPluginCustomTemplates.mios/clevertap_plugin/Sources/clevertap_plugin/CleverTapPluginTemplatePresenter.mios/clevertap_plugin/Sources/clevertap_plugin/include/clevertap_plugin/CleverTapPlugin.hios/clevertap_plugin/Sources/clevertap_plugin/include/clevertap_plugin/CleverTapPluginAppFunctionPresenter.hios/clevertap_plugin/Sources/clevertap_plugin/include/clevertap_plugin/CleverTapPluginCustomTemplates.hios/clevertap_plugin/Sources/clevertap_plugin/include/clevertap_plugin/CleverTapPluginTemplatePresenter.hpubspec.yaml
💤 Files with no reviewable changes (1)
- ios/clevertap_plugin/Sources/clevertap_plugin/CleverTapPluginCustomTemplates.m
✅ Files skipped from review due to trivial changes (1)
- ios/.gitignore
🚧 Files skipped from review as they are similar to previous changes (1)
- pubspec.yaml
…ps and adding migration and troubleshooting guidance.
akashvercetti
left a comment
There was a problem hiding this comment.
@reshab-code we have a new ios sdk version released now, and by the time this release goes out, more versions might have been released. Change the base CT ios sdk version at the time of release
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@doc/Integrate-iOS-SPM.md`:
- Line 121: Update the manual migration instructions for
FlutterGeneratedPluginSwiftPackage to include adding it under the Runner
target’s Frameworks, Libraries, and Embedded Content and configuring it as a
target dependency before creating the Scheme Pre-action Run Script.
- Line 123: Update the “Build fails with missing headers” troubleshooting entry
in Integrate-iOS-SPM.md to focus on verifying SPM linkage and header locations.
Move deployment-target guidance into a separate troubleshooting entry,
preserving the 13.0-or-higher requirement there.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 6806c806-82c7-4ece-8248-584cd5dae537
📒 Files selected for processing (4)
.gitignoredoc/Integrate-iOS-SPM.mdexample/ios/.gitignorepubspec.yaml
| ### 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`. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Flutter Swift Package Manager for-app-developers manual package dependency Verify Frameworks Libraries Embedded Content target dependency
💡 Result:
As of Flutter 3.44, Swift Package Manager (SwiftPM) integration for iOS and macOS is enabled by default [1]. When you run your Flutter app, Flutter automatically manages the necessary SwiftPM dependencies, specifically the FlutterGeneratedPluginSwiftPackage, which handles dependencies for Flutter plugins compatible with SwiftPM [1][2]. Manual integration is generally only required if automatic setup fails or if you are configuring a custom Xcode target [1]. To manually integrate Swift Package Manager for a Flutter app, follow these steps [1]: 1. Add the Package Dependency: In Xcode, navigate to your project and locate the FlutterGeneratedPluginSwiftPackage at the following path: ios/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage [1]. Add this package to your project [1]. 2. Configure Target Dependency: Ensure that the FlutterGeneratedPluginSwiftPackage is correctly added to your desired target (e.g., the Runner target) [1]. 3. Frameworks, Libraries, and Embedded Content: In your Xcode project, go to the General tab for your target and verify that the FlutterGeneratedPluginSwiftPackage appears under the Frameworks, Libraries, and Embedded Content section [1]. If it is missing, add it manually [1]. 4. Pre-action Script: Ensure the Run Prepare Flutter Framework script is configured to run as a pre-action in your Xcode scheme [1]. Verify that the FlutterGeneratedPluginSwiftPackage is set as a target dependency in this process [1]. For "Add-to-App" scenarios where you are embedding a Flutter module into an existing native iOS or macOS application, you should instead use the command line to generate the Swift package: - Run flutter build swift-package --platform ios (or macos) [3][4]. - Add the resulting generated package to your Xcode project and include it in the Frameworks, Libraries, and Embedded Content section of your target [3][4]. - Configure the FLUTTER_SWIFT_PACKAGE_OUTPUT build setting to point to the location of the generated Swift package output [3][4]. If you encounter issues with automatic SwiftPM integration, you can disable it by adding enable-swift-package-manager: false under the flutter section in your pubspec.yaml file, or by running flutter config --no-enable-swift-package-manager [5].
Citations:
- 1: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers
- 2: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/macos/swift_package_manager.dart
- 3: https://docs.flutter.dev/add-to-app/ios/project-setup
- 4: https://docs.flutter.dev/add-to-app/macos/project-setup
- 5: Swift Package Manager integration FAILED! flutter/flutter#186054
🌐 Web query:
site:docs.flutter.dev packages-and-plugins swift-package-manager for-app-developers Manual Swift Package Manager migration Run Script target dependency
💡 Result:
When migrating to or configuring Swift Package Manager (SwiftPM) for Flutter applications, handling Run Script dependencies is a critical step to ensure that Flutter-specific build processes (such as assembling assets and framework generation) are correctly integrated into the Xcode build pipeline [1][2][3]. If you are manually setting up or migrating an iOS or macOS project to use SwiftPM for Flutter, you must configure two specific types of Run Script actions to maintain build integrity [2][3]. 1. Pre-action Run Script (Scheme Level) You must define a pre-action script in your Xcode Scheme to ensure the Flutter framework is prepared before the main build begins [1][2]. - Navigate to Product > Scheme > Edit Scheme... in Xcode [2][3]. - Select Build (in the left sidebar) and expand Pre-actions [2][3]. - Click the + button and select New Run Script Action [2][3]. - In the Provide build settings from dropdown, select your main Runner target [1][2]. - Use the following command (adjusting the path as necessary for your project setup): /bin/sh $FLUTTER_SWIFT_PACKAGE_OUTPUT/Scripts/flutter_integration.sh prebuild 2. Run Script Build Phase (Target Level) To handle assembly during the build process, add a Run Script Phase to your project's target [2][3]. - Navigate to your target's Build Phases tab [2][3]. - Click the + button and select New Run Script Phase [2][3]. - Set the script content to: /bin/sh
Citations:
- 1: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers
- 2: https://docs.flutter.dev/add-to-app/ios/project-setup
- 3: https://docs.flutter.dev/add-to-app/macos/project-setup
- 4: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Target file:"
fd -a 'Integrate-iOS-SPM\.md$' . || true
file="$(fd 'Integrate-iOS-SPM\.md$' . | head -n1 || true)"
if [ -n "${file:-}" ]; then
echo
echo "Relevant lines around 115-130:"
sed -n '115,130p' "$file" | nl -ba -v115
fi
echo
echo "Search for SwiftPM instruction terms in repository:"
rg -n "Framework.?Libraries.?Embedded|Target Dependency|target dependency|FlutterGeneratedPluginSwiftPackage|Run Script|Pre-actions|xcode_backend\.sh prepare" .Repository: CleverTap/clevertap-flutter
Length of output: 295
🏁 Script executed:
#!/bin/sh
set -eu
file="doc/Integrate-iOS-SPM.md"
printf 'Target file: %s\n' "$file"
echo
printf 'Relevant lines around 115-130:\n'
awk 'NR>=115 && NR<=130 { printf "%4d %s\n", NR, $0 }' "$file"
echo
printf 'SwiftPM instruction terms in repository:\n'
rg -n "Framework.?Libraries.?Embedded|Target Dependency|target dependency|FlutterGeneratedPluginSwiftPackage|Run Script|Pre-actions|xcode_backend\.sh prepare" . || trueRepository: CleverTap/clevertap-flutter
Length of output: 2778
Complete the manual SwiftPM linkage steps.
If FlutterGeneratedPluginSwiftPackage must be added manually, also make sure it is present in Frameworks, Libraries, and Embedded Content and configured as a target dependency before adding the Scheme Pre-action Run Script.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@doc/Integrate-iOS-SPM.md` at line 121, Update the manual migration
instructions for FlutterGeneratedPluginSwiftPackage to include adding it under
the Runner target’s Frameworks, Libraries, and Embedded Content and configuring
it as a target dependency before creating the Scheme Pre-action Run Script.
There was a problem hiding this comment.
talked to akash regarding this, no change needed was our conclusion after discussion
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
| - **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`. | ||
| - **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`. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Repository files matching Integrate-iOS-SPM:\n'
fd -a 'Integrate-iOS-SPM\.md$|Package\.swift$|Podfile' . || true
printf '\nRelevant doc snippet:\n'
if [ -f doc/Integrate-iOS-SPM.md ]; then
nl -ba doc/Integrate-iOS-SPM.md | sed -n '100,145p'
fi
printf '\nSearch for missing-header/deployment-target mentions:\n'
rg -n "missing header|header|deployment target|deployment-target|13\.0|FlutterGeneratedPluginSwiftPackage|conditional import|conditional imports" .Repository: CleverTap/clevertap-flutter
Length of output: 454
🌐 Web query:
Flutter SPM App developers minimum platform support iOS 13 missing headers FlutterGeneratedPluginSwiftPackage
💡 Result:
When experiencing build issues with FlutterGeneratedPluginSwiftPackage related to minimum platform versions (e.g., iOS 13) or missing headers, it is typically due to the way Flutter generates the ephemeral Package.swift file for Swift Package Manager (SPM) [1][2][3]. ### Minimum Platform Version Mismatches Flutter's SPM integration sometimes defaults the FlutterGeneratedPluginSwiftPackage platform version to 13.0, ignoring your project's higher deployment target requirements [4][5][3]. This causes build errors if your app or its dependencies require a higher version (e.g., iOS 15.0) [5][3]. To resolve this: 1. Ensure your Xcode project's Minimum Deployment target is set to the required version (e.g., 15.0) in your project settings and Podfile (if still used for other dependencies) [4][5]. 2. Run a Flutter CLI command such as flutter build ios --config-only or flutter run [1][6][3]. These commands trigger the Flutter tool to update the generated Package.swift file to match your project's deployment target [3][7]. 3. Note that building directly from Xcode without running the Flutter CLI first can cause failures because Xcode may use a stale, cached, or default version of the generated Package.swift [2][3]. ### Missing Headers If you encounter missing header errors (often in plugins migrating from CocoaPods to SPM), it is usually because SPM has strict requirements for header directory structure [8][9][10]. To fix header issues: 1. Directory Structure: Ensure your public headers are located in a specific nested path: Sources/<plugin_name>/include/<plugin_name>/YourHeader.h [9][10]. 2. Header Search Paths: If using Objective-C, you may need to explicitly define headerSearchPath in your Package.swift to ensure the compiler can locate these headers [9]. 3. Module Maps: If you are maintaining compatibility with both CocoaPods and SPM, ensure your Package.swift correctly excludes the CocoaPods-specific module map and umbrella header, as SPM manages these automatically [8]. 4. FFI Plugins: If building an FFI plugin, ensure an include folder exists (even if empty, sometimes requiring a .gitkeep file) to satisfy SPM's expectation for public headers [11]. If these issues persist and prevent builds, you can temporarily disable Flutter's SPM integration by adding "disable-swift-package-manager: true" to your pubspec.yaml under the flutter section, or globally via flutter config --no-enable-swift-package-manager [6][11].
Citations:
- 1: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers
- 2: [SwiftPM] Xcode build does not update the generated package's supported platforms flutter/flutter#162196
- 3: [tools] FlutterGeneratedPluginSwiftPackage deployment target not bumped during
flutter pub getflutter/flutter#186804 - 4: [SwiftPM] FlutterGeneratedPluginSwiftPackage uses Flutter's minimum iOS version, instead of looking at project settings flutter/flutter#162072
- 5: FlutterGeneratedPluginSwiftPackage is generated with iOS Deployment Target 13.0 even though Firebase Swift Packages require iOS 15.0 flutter/flutter#189422
- 6: Migrating from podfiles to Package.swift: incompatibility in iOS versions flutter/flutter#162241
- 7: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/macos/swift_package_manager.dart
- 8: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
- 9: https://medium.com/@lozhkovoi/migrating-a-flutter-plugin-from-cocoapods-to-spm-one-codebase-two-package-managers-920f8728384d
- 10: https://shadatrahman.github.io/posts/flutter-plugin-swift-package-manager-migration/
- 11: [SPM] Public headers issue when using SPM in ffi Plugins flutter/flutter#174420
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Relevant doc snippet:\n'
awk 'NR>=110 && NR<=130 {printf "%6d\t%s\n", NR, $0}' doc/Integrate-iOS-SPM.md
printf '\nPackage.swift header/public headers section:\n'
awk '{printf "%6d\t%s\n", NR, $0}' ios/clevertap_plugin/Package.swift
printf '\nPodfile platform/deployment settings and generated package mentions:\n'
awk '{printf "%6d\t%s\n", NR, $0}' example/ios/Podfile | rg -n "platform|ios|FlutterGeneratedPluginSwiftPackage|package" || true
printf '\nDoc mentions of FlutterGeneratedPluginSwiftPackage and missing headers:\n'
rg -n "FlutterGeneratedPluginSwiftPackage|missing header|header|deployment target|13\.0" doc/Integrate-iOS-SPM.md || true
printf '\nSearch for conditional import mentions in doc and plugin source headers package config:\n'
rg -n "conditional import|conditional imports|import.*conditional|Swift\(`#if`" doc ios example -S || trueRepository: CleverTap/clevertap-flutter
Length of output: 4741
Separate missing-header and deployment-target troubleshooting.
Deployment target errors are handled separately. Missing-header errors need SPM linkage and header-location checks, not just a 13.0 deployment target.
Suggested documentation update
-- **Build fails with missing headers**: Verify your deployment target is `13.0` or higher in both your Xcode project and `Podfile`/`Package.swift`.
+- **Build reports an iOS deployment-target error**: Verify that your Xcode project and `Podfile`/`Package.swift` use an iOS deployment target of `13.0` or higher.
+- **Build fails with missing headers**: Verify that `FlutterGeneratedPluginSwiftPackage` is linked to the `Runner` target and that the conditional imports match the selected package manager.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - **Build fails with missing headers**: Verify your deployment target is `13.0` or higher in both your Xcode project and `Podfile`/`Package.swift`. | |
| - **Build reports an iOS deployment-target error**: Verify that your Xcode project and `Podfile`/`Package.swift` use an iOS deployment target of `13.0` or higher. | |
| - **Build fails with missing headers**: Verify that `FlutterGeneratedPluginSwiftPackage` is linked to the `Runner` target and that the conditional imports match the selected package manager. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@doc/Integrate-iOS-SPM.md` at line 123, Update the “Build fails with missing
headers” troubleshooting entry in Integrate-iOS-SPM.md to focus on verifying SPM
linkage and header locations. Move deployment-target guidance into a separate
troubleshooting entry, preserving the 13.0-or-higher requirement there.
There was a problem hiding this comment.
talked to akash regarding this, no change needed was our conclusion after discussion
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
| ### 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`. |
| - **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`. | ||
| - **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`. |
…te as per docs, adds spm builds to gitignore
| .product(name: "FlutterFramework", package: "FlutterFramework"), | ||
| .product(name: "CleverTapSDK", package: "clevertap-ios-sdk") | ||
| ], | ||
| publicHeadersPath: "include/clevertap_plugin", |
There was a problem hiding this comment.
why is publicHeadersPath added even if not stated in flutter docs? Is it needed? Have you tested this on sample app?
There was a problem hiding this comment.
publicHeadersPath is required for Objective-C targets in SPM as iit tells the package manager where the public headers are so it can generate a module map. The headers physically live at Sources/clevertap_plugin/include/clevertap_plugin/ and the path "include/clevertap_plugin" is relative to that sources dir. Without it, ObjC imports would break. It was tested and verified in the example app with SPM enabled.
| 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 from v4.2.0 ships a `Package.swift` alongside its podspec, so both package managers resolve the same native SDK version (`CleverTap-iOS-SDK 7.8.1`). | ||
|
|
||
| > **Minimum requirements for SPM integration** | ||
| > - Flutter 3.24+ (opt-in) - enabled by default from Flutter 3.44 |
There was a problem hiding this comment.
Since we have mentioned on doc it is supported from 3.24, have you tested on lower versions with this package, like 3.35 version?
There was a problem hiding this comment.
Testing was done on Flutter 3.41.9 with SPM opt-in enabled - which is in the 3.24-3.43 range. Flutter 3.24 and 3.35 were not tested specifically. We can either mention in the docs that it was tested on 3.41.9 and enabled by default from Flutter 3.44 or explicitly test on lower version whatever you suggest
nishant-clevertap
left a comment
There was a problem hiding this comment.
resolve merge conflict on this PR
nishant-clevertap
left a comment
There was a problem hiding this comment.
Check for debug and release build on iPhone device, and then try to archive the app after migrating to SPM, on latest flutter version and lower versions also
…clevertap_plugin.m.
Summary
Adds Swift Package Manager (SPM) support to the CleverTap Flutter plugin iOS layer,
alongside the existing CocoaPods integration. Both package managers are supported
simultaneously — consumers choose based on their project setup.
Changes
pubspec.yaml— AddedswiftPackageName: clevertap_pluginunderios:toenable Flutter's SPM plugin detection
ios/clevertap_plugin/Package.swift— New SPM package manifest declaringCleverTapSDK(≥ 7.6.0) as a dependency with public headers path and search pathsios/clevertap_plugin/Classes/— Symlink pointing to../Classesso the SPMtarget and CocoaPods target share the same source files
ios/Classes/CleverTapPlugin.m— Added__has_includeguards around<CleverTapSDK/CleverTap.h>and<clevertap_plugin/CleverTapPlugin.h>forcompatibility under both build systems
ios/Classes/CleverTapPluginCustomTemplates.m— Same__has_includeguardsfor
CTJsonTemplateProducer.handCTCustomTemplatesManager.hios/clevertap_plugin.podspec— Narrowed public header file patternsNotes
clevertap-ios-sdkat7.7.0(satisfiesfrom: "7.6.0"constraint)below this are auto-promoted with a build log notice
clevertap-ios-sdkdirectly at a future v8 major,SPM will fail with: "Dependencies could not be resolved because root depends on
'clevertap-ios-sdk' 8.0.0..<9.0.0 and 'clevertap_plugin' depends on
'clevertap-ios-sdk' 7.6.0..<8.0.0." — this is expected behavior
Test Results
Build Verification (automated — CI)
flutter build ios --no-codesignsucceedsclevertap-ios-sdk 7.6.0resolved via SPMnmshows no CleverTap duplicatesCleverTapSDK.frameworkpresent in.app/Frameworks/otool -Lconfirms CleverTapSDK dylibIntegration Tests (simulator + staging account)
CleverTap: Initializing...in console, no crashonUserLoginpayload confirmed delivered to dashboardsyncVariables()requires a debug-signed build;syncVariablesinProd(false)unblocks in simulatorCocoaPods Regression (manual)
Podfile.lockshowsCleverTap-iOS-SDK (7.6.0), clean build3.8.1 → 4.0.0viapod update; all existing API calls compile and runSPM Regression (manual)
Package.resolvedshowsclevertap-ios-sdk 7.7.0, clean buildMigration Path Tests (manual)
pod deintegrate+ SPM build succeededpod installrestored CocoaPods build cleanlySummary by CodeRabbit
New Features
Bug Fixes
Documentation