feat: add experimental Swift Package Manager (SPM) support#330
feat: add experimental Swift Package Manager (SPM) support#330
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Swift Package Manager (SPM) support across the iOS-enabled plugins by introducing per-plugin Package.swift manifests and migrating Capacitor iOS plugins to the Swift CAPBridgedPlugin registration style.
Changes:
- Add
Package.swiftfor each plugin and wire in Capacitor + (where needed) ML Kit SPM dependencies. - Migrate iOS plugin registration from
CAP_PLUGINObjective-C bridge files toCAPBridgedPlugin(identifier,jsName,pluginMethods) and remove obsolete.h/.mfiles + Xcode project references. - Add Turbo/CI scripts for SPM dependency resolution and update plugin packaging/gitignore rules to include SPM artifacts.
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| turbo.json | Adds a new Turbo task (ios:spm:install) to support SPM dependency resolution. |
| package.json | Adds root scripts to run SPM install tasks (including affected/all variants) via Turbo. |
| README.md | Removes the top-level warning claiming SPM is not supported. |
| .github/workflows/ci.yml | Adds CI steps to resolve SPM dependencies and tweaks Turbo SCM base configuration. |
| packages/barcode-scanning/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/barcode-scanning/ios/Plugin/BarcodeScannerPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/barcode-scanning/ios/Plugin/BarcodeScannerPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/barcode-scanning/ios/Plugin/BarcodeScannerPlugin.h | Removes obsolete public header. |
| packages/barcode-scanning/ios/Plugin.xcodeproj/project.pbxproj | Cleans removed .h/.m references from the Xcode project. |
| packages/barcode-scanning/Package.swift | Adds SPM manifest for the barcode scanning plugin (Capacitor + MLKit). |
| packages/barcode-scanning/.gitignore | Ignores common SPM-generated files/directories. |
| packages/document-scanner/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/document-scanner/Package.swift | Adds SPM manifest for the document scanner plugin. |
| packages/face-detection/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/face-detection/ios/Plugin/FaceDetectionPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/face-detection/ios/Plugin/FaceDetectionPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/face-detection/ios/Plugin/FaceDetectionPlugin.h | Removes obsolete public header. |
| packages/face-detection/ios/Plugin.xcodeproj/project.pbxproj | Cleans removed .h/.m references from the Xcode project. |
| packages/face-detection/Package.swift | Adds SPM manifest for the face detection plugin (Capacitor + MLKit). |
| packages/face-detection/.gitignore | Ignores common SPM-generated files/directories. |
| packages/face-mesh-detection/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/face-mesh-detection/ios/Plugin/FaceMeshDetectionPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/face-mesh-detection/ios/Plugin/FaceMeshDetectionPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/face-mesh-detection/ios/Plugin/FaceMeshDetectionPlugin.h | Removes obsolete public header. |
| packages/face-mesh-detection/ios/Plugin.xcodeproj/project.pbxproj | Cleans removed .h/.m references from the Xcode project. |
| packages/face-mesh-detection/Package.swift | Adds SPM manifest for the face mesh detection plugin. |
| packages/face-mesh-detection/.gitignore | Ignores common SPM-generated files/directories. |
| packages/selfie-segmentation/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/selfie-segmentation/ios/Plugin/SelfieSegmentationPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/selfie-segmentation/ios/Plugin/SelfieSegmentationPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/selfie-segmentation/ios/Plugin/SelfieSegmentationPlugin.h | Removes obsolete public header. |
| packages/selfie-segmentation/ios/Plugin.xcodeproj/project.pbxproj | Cleans removed .h/.m references from the Xcode project. |
| packages/selfie-segmentation/Package.swift | Adds SPM manifest for the selfie segmentation plugin (Capacitor + MLKit). |
| packages/selfie-segmentation/.gitignore | Ignores common SPM-generated files/directories. |
| packages/subject-segmentation/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/subject-segmentation/ios/Plugin/SubjectSegmentationPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/subject-segmentation/ios/Plugin/SubjectSegmentationPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/subject-segmentation/Package.swift | Adds SPM manifest for the subject segmentation plugin. |
| packages/translation/package.json | Publishes Package.swift and adds an ios:spm:install script. |
| packages/translation/ios/Plugin/TranslationPlugin.swift | Migrates plugin registration to CAPBridgedPlugin and lists exposed methods. |
| packages/translation/ios/Plugin/TranslationPlugin.m | Removes Objective-C bridge macro registration file. |
| packages/translation/ios/Plugin/TranslationPlugin.h | Removes obsolete public header. |
| packages/translation/ios/Plugin.xcodeproj/project.pbxproj | Cleans removed .h/.m references from the Xcode project. |
| packages/translation/Package.swift | Adds SPM manifest for the translation plugin (Capacitor + MLKit). |
| packages/translation/.gitignore | Ignores common SPM-generated files/directories. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@capacitor-mlkit/barcode-scanning
@capacitor-mlkit/document-scanner
@capacitor-mlkit/face-detection
@capacitor-mlkit/face-mesh-detection
@capacitor-mlkit/selfie-segmentation
@capacitor-mlkit/subject-segmentation
@capacitor-mlkit/translation
commit: |
|
@robingenz Thanks. I'm getting Xcode build error resolving package versions after installing this plugin. |
|
@jacobg Would you be willing to debug it and create a PR based on this branch? |
|
@robingenz I started to look at it. I tried Android first, since this PR shouldn't affect that, and I'm getting build error: BarcodeScanner.java imports ListenableFuture in that package. That package is guava, and I'm not sure how it would ever work since guava is not listed as a maven dependency. Can you please clarify that? Thanks. |
|
@jacobg Nothing has changed for Android (feel free to check out the changes in this PR). This must be a local configuration issue. |
@robingenz It was because I was overriding to use camerax 1.6.0 whereas capacitor-mlkit by default using 1.5.2. It seems 1.5.2 exposed com.google.common.util.concurrent.ListenableFuture that you can import, whereas 1.6.0 no longer does. If capacitor-mlkit is directly using ListenableFuture shouldn't it declare it as a dependency? |
|
@jacobg I will check that. Let's focus on iOS in this PR. Did you had a chance to give it a try on iOS? |
|
@robingenz I figured out the issue was due to this PR using: whereas the latest version since January 2026 is version 9. It caused two issues:
I locally patched my node_modules for this PR to use version 9, and iOS works great now! Did you intentionally use version 8, or are you ok if I create a PR with version 9? |
|
@robingenz There is some transitive dependency issue between MLKit and other Google/Firebase packages. It's discussed here: I'm not sure how you might see version 8 working now. Maybe it's because I also have direct dependencies on latest version of Firebase. In any event, wouldn't this SPM PR be a major release that can coincide with updating to version 9? |
|
@robingenz I have a working branch here: And am running the barcode scanner plugin based on published package here: |
Yes, we consider updating the native SDK a major change. I’ll update this PR to use ML Kit v9 so you can use the pre-release in the meantime, but we’ll need to hold off on merging until Capacitor 9 is published. |
|
@robingenz Oh I didn't know you were referring to major version of Capacitor. I thought you meant major version of capacitor-mlkit. So you tie the two together for major releases? Does that potentially stifle plugin innovation and cadence? |
|
@jacobg Sure, that’s limiting, but it’s become the standard that the major version of Capacitor and its plugins match, to make it easier for developers to judge compatibility (see the official plugin versions). |
|
@robingenz ok |
Summary
Adds Swift Package Manager (SPM) support to all seven iOS-enabled plugins:
barcode-scanning,document-scanner,face-detection,face-mesh-detection,selfie-segmentation,subject-segmentation, andtranslation.Changes
Package.swiftmanifest for each plugin (iOS 15, Swift 5.9, Capacitor 8+).d-date/google-mlkit-swiftpm, since Google does not officially ship ML Kit via SPM. Version pinned via.upToNextMinor(from: "8.0.0")to match the existing~> 8.0.0CocoaPods constraint.CAP_PLUGIN/CAP_PLUGIN_METHOD) to the SwiftCAPBridgedPluginprotocol. Addedidentifier,jsName, andpluginMethodsproperties listing every exposed method.*.h/*.mbridge files and cleaned their entries from each Xcodeproject.pbxproj.Package.resolved,/.build,/Packages,.swiftpm/...,.netrc) to each plugin's.gitignore.Package.swiftto each plugin'sfilesarray inpackage.jsonand a newios:spm:installscript.Note: the
language-identificationpackage has no iOS implementation, so it is unaffected.Test plan
npm run verify:iosfor each plugin continues to succeed via CocoaPodshttps://github.com/capawesome-team/capacitor-mlkit.git) and confirm the library product resolves and the build succeedsGoogleMLKit/* ~> 8.0.0