Skip to content

Add Swift Package Manager (SPM) support for Flutter-SDK#356

Open
reshab-code wants to merge 13 commits into
developfrom
task/SDK-5694-spm-support-flutter-sdk
Open

Add Swift Package Manager (SPM) support for Flutter-SDK#356
reshab-code wants to merge 13 commits into
developfrom
task/SDK-5694-spm-support-flutter-sdk

Conversation

@reshab-code

@reshab-code reshab-code commented Jun 2, 2026

Copy link
Copy Markdown

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 — Added swiftPackageName: clevertap_plugin under ios: to
    enable Flutter's SPM plugin detection
  • ios/clevertap_plugin/Package.swift — New SPM package manifest declaring
    CleverTapSDK (≥ 7.6.0) as a dependency with public headers path and search paths
  • ios/clevertap_plugin/Classes/ — Symlink pointing to ../Classes so the SPM
    target and CocoaPods target share the same source files
  • ios/Classes/CleverTapPlugin.m — Added __has_include guards around
    <CleverTapSDK/CleverTap.h> and <clevertap_plugin/CleverTapPlugin.h> for
    compatibility under both build systems
  • ios/Classes/CleverTapPluginCustomTemplates.m — Same __has_include guards
    for CTJsonTemplateProducer.h and CTCustomTemplatesManager.h
  • ios/clevertap_plugin.podspec — Narrowed public header file patterns

Notes

  • SPM resolves clevertap-ios-sdk at 7.7.0 (satisfies from: "7.6.0" constraint)
  • Flutter SPM tooling enforces a minimum deployment target of iOS 13.0; projects
    below this are auto-promoted with a build log notice
  • If a consumer app declares clevertap-ios-sdk directly 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)

  • TC-B01 CocoaPods clean build — flutter build ios --no-codesign succeeds
  • TC-B02 SPM clean build — build succeeds, clevertap-ios-sdk 7.6.0 resolved via SPM
  • TC-B03 No duplicate symbols (SPM) — nm shows no CleverTap duplicates
  • TC-B04 Frameworks correctly embedded — CleverTapSDK.framework present in .app/Frameworks/
  • TC-B05 Archive / IPA creation — IPA created, otool -L confirms CleverTapSDK dylib
  • TC-B06 Modular headers build (CocoaPods) — no "non-modular header" errors

Integration Tests (simulator + staging account)

  • TC-I01 SDK initializes without crash — CleverTap: Initializing... in console, no crash
  • TC-I02 User login event — onUserLogin payload confirmed delivered to dashboard
  • TC-I03 Push notification permission prompt — system dialog appeared, no crash
  • TC-I04 In-app notification render — event fired and accepted by server; inapp renders fine
  • TC-I05 App Inbox initialization — works
  • TC-I06 Custom templates registration — not validated
  • TC-I07 CTVar sync — syncVariables() requires a debug-signed build; syncVariablesinProd(false) unblocks in simulator ⚠️

CocoaPods Regression (manual)

  • TC-M01 Fresh install — Podfile.lock shows CleverTap-iOS-SDK (7.6.0), clean build
  • TC-M02 Upgrade from 3.x — upgraded 3.8.1 → 4.0.0 via pod update; all existing API calls compile and run

SPM Regression (manual)

  • TC-S01 Fresh SPM project — Package.resolved shows clevertap-ios-sdk 7.7.0, clean build
  • TC-S02 Single copy of SDK in graph — requires Xcode Package Dependencies pane verification
  • TC-S03 Clean DerivedData rebuild — requires manual Xcode rebuild

Migration Path Tests (manual)

  • TC-E01 CocoaPods → SPM migration — pod deintegrate + SPM build succeeded
  • TC-E02 SPM → CocoaPods rollback — pod install restored CocoaPods build cleanly
  • TC-E03 Deployment target below 12.0 — Flutter auto-promotes to 13.0 with build notice; no error, no crash (amended from original pass criteria)
  • TC-E04 Version conflict from direct v8 dependency — SPM emits clear, readable conflict error (expected failure — documented above)

Summary by CodeRabbit

  • New Features

    • Added Swift Package Manager support for the iOS plugin.
  • Improvements

    • Enhanced iOS build system compatibility with safer, conditional header imports.
    • Removed hardcoded US English locale from the example app, allowing system locale to be used.
  • Chores

    • Updated iOS build configuration and header file structure.

@francispereira

francispereira commented Jun 2, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces Swift Package Manager (SwiftPM) support for the CleverTap Flutter plugin by restructuring iOS header management, adding flexible header imports via preprocessor checks, and creating a complete SwiftPM package manifest. The changes maintain backward compatibility while enabling modern package management, and include a minor locale fix in the example application.

Changes

Swift Package Manager Integration for CleverTap Flutter Plugin

Layer / File(s) Summary
Flexible header imports via preprocessor checks
example/ios/Runner/AppDelegate.m, ios/Classes/CleverTapPlugin.m, ios/Classes/CleverTapPluginCustomTemplates.m
Objective-C implementation files now use __has_include() checks to select between module-style SDK headers (<CleverTapSDK/...>) and local header fallbacks, enabling the build to adapt to different header layouts without code modifications.
Header symlink consolidation in include directory
ios/Classes/include/CleverTapPlugin.h, ios/Classes/include/CleverTapPluginAppFunctionPresenter.h, ios/Classes/include/CleverTapPluginCustomTemplates.h, ios/Classes/include/CleverTapPluginTemplatePresenter.h
Four public headers in the include directory are converted to symlinks pointing to their parent directory counterparts, establishing a single canonical location for each header while maintaining the expected include-path interface.
Swift Package Manager configuration and build integration
ios/clevertap_plugin/Package.swift, ios/clevertap_plugin/Classes, ios/clevertap_plugin.podspec, pubspec.yaml
Complete SwiftPM package manifest is created with clevertap-plugin library product, Classes source path, include public headers path, and a dependency on CleverTap/clevertap-ios-sdk@7.6.0. The plugin podspec is updated to exclude the include directory and limit public headers to Classes/*.h. A Classes symlink is added to the package structure. The Flutter plugin registration in pubspec.yaml now includes swiftPackageName: clevertap_plugin to signal SPM support.
Toast locale configuration cleanup
example/lib/main.dart
The hardcoded locale: const Locale('en', 'US') parameter is removed from the StyledToast widget, allowing the toast to inherit the device or application locale setting instead of being pinned to US English.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • Add Swift Package Manager support #346: The main changes directly enable Swift Package Manager support through the addition of Package.swift, pubspec.yaml swiftPackageName configuration, and iOS header/include restructuring that form the core migration requested in that issue.

Suggested reviewers

  • akashvercetti
  • nishant-clevertap
  • KambleSonam

Poem

🐰 A rabbit hops through header files so bright,
Symlinks dance and SwiftPM takes flight,
Preprocessor checks guide the way,
With flexible imports, come what may,
The package now sings—clean, lean, and right! 📦✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Swift Package Manager (SPM) support for Flutter-SDK' directly and clearly summarizes the main objective of the PR, which is to add SPM support to the CleverTap Flutter plugin while maintaining CocoaPods compatibility.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/SDK-5694-spm-support-flutter-sdk

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@akashvercetti

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between d716be5 and dfd2cf9.

📒 Files selected for processing (12)
  • example/ios/Runner/AppDelegate.m
  • example/lib/main.dart
  • ios/Classes/CleverTapPlugin.m
  • ios/Classes/CleverTapPluginCustomTemplates.m
  • ios/Classes/include/CleverTapPlugin.h
  • ios/Classes/include/CleverTapPluginAppFunctionPresenter.h
  • ios/Classes/include/CleverTapPluginCustomTemplates.h
  • ios/Classes/include/CleverTapPluginTemplatePresenter.h
  • ios/clevertap_plugin.podspec
  • ios/clevertap_plugin/Classes
  • ios/clevertap_plugin/Package.swift
  • pubspec.yaml
💤 Files with no reviewable changes (1)
  • example/lib/main.dart

Comment on lines +14 to 17
s.exclude_files = 'Classes/include/**/*'
s.public_header_files = 'Classes/*.h'
s.dependency 'Flutter'
s.dependency 'CleverTap-iOS-SDK', '7.6.0'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== podspec dependency =="
sed -n '13,18p' ios/clevertap_plugin.podspec

echo
echo "== SwiftPM dependency =="
sed -n '1,220p' ios/clevertap_plugin/Package.swift | rg -n "CleverTap|from:|upToNext|exact|branch|revision"

echo
echo "Expected:"
echo "- Both package managers should enforce the same native SDK version policy."
echo "- If SwiftPM uses a 7.x range, CocoaPods should use an equivalent constraint."
echo "- If reproducibility matters more, pin both sides to the same exact version."

Repository: CleverTap/clevertap-flutter

Length of output: 821


Align the CleverTap iOS SDK version constraints across CocoaPods and SwiftPM.

ios/clevertap_plugin.podspec pins CleverTap-iOS-SDK to exact 7.6.0, while ios/clevertap_plugin/Package.swift uses SwiftPM from: "7.6.0" for clevertap-ios-sdk—so the same Flutter plugin can build against different CleverTapSDK versions depending on whether CocoaPods or SwiftPM is used. Make both package managers follow the same version policy (pin both sides to the same exact version, or use equivalent ranges).

🤖 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 `@ios/clevertap_plugin.podspec` around lines 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.

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.

5 participants