Skip to content

feat: add Swift Package Manager (SPM) support for iOS#870

Merged
fbernaly merged 5 commits into
flutter-ml:developfrom
arrrrny:feature/swift-package-manager
Jun 4, 2026
Merged

feat: add Swift Package Manager (SPM) support for iOS#870
fbernaly merged 5 commits into
flutter-ml:developfrom
arrrrny:feature/swift-package-manager

Conversation

@arrrrny

@arrrrny arrrrny commented Jun 4, 2026

Copy link
Copy Markdown

Summary

This PR adds Swift Package Manager (SPM) support for iOS, resolving issue #868.

Problem

All ML Kit plugins trigger a warning when building for iOS with Flutter 3.44+:

The following plugins do not support Swift Package Manager for ios: google_mlkit_pose_detection, google_mlkit_commons, ... (22 packages total). This will become an error in a future version of Flutter.

CocoaPods is now in maintenance mode and Swift Package Manager will be required for Flutter iOS builds.

Solution

Added Package.swift manifests for 22 ML Kit packages with iOS implementations.

Important: Package.swift must be placed at ios/<package_name>/Package.swift, NOT at ios/Package.swift.

Important: The package reference must use the URL-derived name google-mlkit-swiftpm, not GoogleMLKitSwiftPM.

Verification

cd packages/example && flutter pub get
# All plugins found for ios are Swift Packages

Usage

No additional configuration needed - Flutter 3.44+ automatically detects and uses Package.swift files when building for iOS.

Uses the community-maintained d-date/google-mlkit-swiftpm package for ML Kit binary dependencies.

For more information, see: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors

arrrrny added a commit to arrrrny/zikzak_ml_kit_flutter that referenced this pull request Jun 4, 2026
arrrrny added a commit to arrrrny/zikzak_ml_kit_flutter that referenced this pull request Jun 4, 2026
This extends PR flutter-ml#870 to cover all ML Kit packages that need Swift Package Manager
support for Flutter 3.44+ iOS builds.

Packages with MLKit dependencies:
- google_mlkit_barcode_scanning: MLKitBarcodeScanning
- google_mlkit_digital_ink_recognition: MLKitDigitalInkRecognition
- google_mlkit_document_scanner: MLKitDocumentScanner
- google_mlkit_entity_extraction: MLKitEntityExtraction
- google_mlkit_face_detection: MLKitFaceDetection
- google_mlkit_face_mesh_detection: MLKitFaceMesh
- google_mlkit_image_labeling: MLKitImageLabeling, MLKitImageLabelingCommon
- google_mlkit_language_id: MLKitLanguageID
- google_mlkit_object_detection: MLKitObjectDetection
- google_mlkit_selfie_segmentation: MLKitSegmentationSelfie
- google_mlkit_smart_reply: MLKitSmartReply
- google_mlkit_text_recognition: MLKitTextRecognition
- google_mlkit_translation: MLKitTranslate
- google_mlkit_subject_segmentation: MLKitSegmentationSubject

GenAI packages (iOS stubs only) - no MLKit dependencies:
- google_mlkit_genai_image_description
- google_mlkit_genai_prompt
- google_mlkit_genai_proofreading
- google_mlkit_genai_rewriting
- google_mlkit_genai_speech_recognition
- google_mlkit_genai_summarization

All packages now support Swift Package Manager using d-date/google-mlkit-swiftpm
as the MLKit binary distribution.

Fixes issue flutter-ml#868
This extends PR flutter-ml#870 to cover all ML Kit packages that need Swift Package Manager
support for Flutter 3.44+ iOS builds.

Packages with MLKit dependencies:
- google_mlkit_barcode_scanning: MLKitBarcodeScanning
- google_mlkit_digital_ink_recognition: MLKitDigitalInkRecognition
- google_mlkit_document_scanner: MLKitDocumentScanner
- google_mlkit_entity_extraction: MLKitEntityExtraction
- google_mlkit_face_detection: MLKitFaceDetection
- google_mlkit_face_mesh_detection: MLKitFaceMesh
- google_mlkit_image_labeling: MLKitImageLabeling, MLKitImageLabelingCommon
- google_mlkit_language_id: MLKitLanguageID
- google_mlkit_object_detection: MLKitObjectDetection
- google_mlkit_selfie_segmentation: MLKitSegmentationSelfie
- google_mlkit_smart_reply: MLKitSmartReply
- google_mlkit_text_recognition: MLKitTextRecognition
- google_mlkit_translation: MLKitTranslate
- google_mlkit_subject_segmentation: MLKitSegmentationSubject

GenAI packages (iOS stubs only) - no MLKit dependencies:
- google_mlkit_genai_image_description
- google_mlkit_genai_prompt
- google_mlkit_genai_proofreading
- google_mlkit_genai_rewriting
- google_mlkit_genai_speech_recognition
- google_mlkit_genai_summarization

All packages now support Swift Package Manager using d-date/google-mlkit-swiftpm
as the MLKit binary distribution.

Fixes issue flutter-ml#868
@arrrrny arrrrny force-pushed the feature/swift-package-manager branch from 5bde8cd to 9457d85 Compare June 4, 2026 05:59
arrrrny added 4 commits June 4, 2026 09:00
Flutter expects Package.swift at ios/<package_name>/Package.swift, not ios/Package.swift.

Changes:
- Move all 22 Package.swift files to ios/<package_name>/ subdirectories
- Update path from 'Classes' to '../Classes' for correct relative path resolution

This fixes Swift Package Manager detection for all ML Kit plugins.
Swift Package Manager uses the URL-derived package name, not the @objc product name.
Changed all package references from 'GoogleMLKitSwiftPM' to 'google-mlkit-swiftpm'.

Also fixed GenAI packages (empty dependencies) to have valid SPM format.
@fbernaly fbernaly changed the title Feat: add Swift Package Manager (SPM) support for iOS feat: add Swift Package Manager (SPM) support for iOS Jun 4, 2026
@fbernaly

fbernaly commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

@arrrrny: thanks for the PR, I will merge after #862

Copilot AI 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.

Pull request overview

This PR adds Swift Package Manager (SPM) manifests to the repository’s iOS Flutter plugins so Flutter 3.44+ can resolve them as Swift Packages (avoiding the “plugins do not support Swift Package Manager for ios” warning that will become an error). It also adjusts the example iOS project to move away from CocoaPods integration and updates the example lockfile.

Changes:

  • Added ios/<plugin_name>/Package.swift manifests for multiple ML Kit plugins, pointing to d-date/google-mlkit-swiftpm products.
  • Updated the example iOS Xcode project to remove CocoaPods build phases / linkage and removed the Pods xcconfig include from the Profile configuration.
  • Regenerated packages/example/pubspec.lock (dependency versions + SDK constraint metadata).

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/google_mlkit_translation/ios/google_mlkit_translation/Package.swift Adds SPM manifest for the translation plugin and declares ML Kit Translate-related products.
packages/google_mlkit_text_recognition/ios/google_mlkit_text_recognition/Package.swift Adds SPM manifest for text recognition plugin with ML Kit Text Recognition products.
packages/google_mlkit_subject_segmentation/ios/google_mlkit_subject_segmentation/Package.swift Adds SPM manifest for subject segmentation plugin with segmentation products.
packages/google_mlkit_smart_reply/ios/google_mlkit_smart_reply/Package.swift Adds SPM manifest for smart reply plugin with Natural Language-related products.
packages/google_mlkit_selfie_segmentation/ios/google_mlkit_selfie_segmentation/Package.swift Adds SPM manifest for selfie segmentation plugin with segmentation products.
packages/google_mlkit_pose_detection/ios/google_mlkit_pose_detection/Package.swift Adds SPM manifest for pose detection plugin with pose detection products.
packages/google_mlkit_object_detection/ios/google_mlkit_object_detection/Package.swift Adds SPM manifest for object detection plugin with object detection products.
packages/google_mlkit_language_id/ios/google_mlkit_language_id/Package.swift Adds SPM manifest for language ID plugin with Natural Language-related products.
packages/google_mlkit_image_labeling/ios/google_mlkit_image_labeling/Package.swift Adds SPM manifest for image labeling plugin with image labeling products.
packages/google_mlkit_genai_summarization/ios/google_mlkit_genai_summarization/Package.swift Adds SPM manifest for genai summarization iOS stub target (no ML Kit deps).
packages/google_mlkit_genai_speech_recognition/ios/google_mlkit_genai_speech_recognition/Package.swift Adds SPM manifest for genai speech recognition iOS stub target (no ML Kit deps).
packages/google_mlkit_genai_rewriting/ios/google_mlkit_genai_rewriting/Package.swift Adds SPM manifest for genai rewriting iOS stub target (no ML Kit deps).
packages/google_mlkit_genai_proofreading/ios/google_mlkit_genai_proofreading/Package.swift Adds SPM manifest for genai proofreading iOS stub target (no ML Kit deps).
packages/google_mlkit_genai_prompt/ios/google_mlkit_genai_prompt/Package.swift Adds SPM manifest for genai prompt iOS stub target (no ML Kit deps).
packages/google_mlkit_genai_image_description/ios/google_mlkit_genai_image_description/Package.swift Adds SPM manifest for genai image description iOS stub target (no ML Kit deps).
packages/google_mlkit_face_mesh_detection/ios/google_mlkit_face_mesh_detection/Package.swift Adds SPM manifest for face mesh detection plugin with face mesh products.
packages/google_mlkit_face_detection/ios/google_mlkit_face_detection/Package.swift Adds SPM manifest for face detection plugin with face detection products.
packages/google_mlkit_entity_extraction/ios/google_mlkit_entity_extraction/Package.swift Adds SPM manifest for entity extraction plugin with entity extraction products.
packages/google_mlkit_document_scanner/ios/google_mlkit_document_scanner/Package.swift Adds SPM manifest for document scanner plugin with document scanner products.
packages/google_mlkit_digital_ink_recognition/ios/google_mlkit_digital_ink_recognition/Package.swift Adds SPM manifest for digital ink recognition plugin with digital ink products.
packages/google_mlkit_commons/ios/google_mlkit_commons/Package.swift Adds SPM manifest for shared iOS commons plugin with core vision/common products.
packages/google_mlkit_barcode_scanning/ios/google_mlkit_barcode_scanning/Package.swift Adds SPM manifest for barcode scanning plugin with barcode scanning products.
packages/example/pubspec.lock Updates locked dependency versions and SDK metadata for the example app.
packages/example/ios/Runner.xcodeproj/project.pbxproj Removes CocoaPods build phases and the Pods static lib from the example iOS project.
packages/example/ios/Flutter/Profile.xcconfig Drops Profile configuration include of the Pods xcconfig.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fbernaly fbernaly merged commit 251303a into flutter-ml:develop Jun 4, 2026
2 of 4 checks passed
fbernaly pushed a commit that referenced this pull request Jun 4, 2026
* feat: add Swift Package Manager support for all ML Kit packages

This extends PR #870 to cover all ML Kit packages that need Swift Package Manager
support for Flutter 3.44+ iOS builds.

Packages with MLKit dependencies:
- google_mlkit_barcode_scanning: MLKitBarcodeScanning
- google_mlkit_digital_ink_recognition: MLKitDigitalInkRecognition
- google_mlkit_document_scanner: MLKitDocumentScanner
- google_mlkit_entity_extraction: MLKitEntityExtraction
- google_mlkit_face_detection: MLKitFaceDetection
- google_mlkit_face_mesh_detection: MLKitFaceMesh
- google_mlkit_image_labeling: MLKitImageLabeling, MLKitImageLabelingCommon
- google_mlkit_language_id: MLKitLanguageID
- google_mlkit_object_detection: MLKitObjectDetection
- google_mlkit_selfie_segmentation: MLKitSegmentationSelfie
- google_mlkit_smart_reply: MLKitSmartReply
- google_mlkit_text_recognition: MLKitTextRecognition
- google_mlkit_translation: MLKitTranslate
- google_mlkit_subject_segmentation: MLKitSegmentationSubject

GenAI packages (iOS stubs only) - no MLKit dependencies:
- google_mlkit_genai_image_description
- google_mlkit_genai_prompt
- google_mlkit_genai_proofreading
- google_mlkit_genai_rewriting
- google_mlkit_genai_speech_recognition
- google_mlkit_genai_summarization

All packages now support Swift Package Manager using d-date/google-mlkit-swiftpm
as the MLKit binary distribution.

Fixes issue #868

* feat: add missing Package.swift for google_mlkit_commons and google_mlkit_pose_detection

* fix: move Package.swift to correct Swift Package Manager path

Flutter expects Package.swift at ios/<package_name>/Package.swift, not ios/Package.swift.

Changes:
- Move all 22 Package.swift files to ios/<package_name>/ subdirectories
- Update path from 'Classes' to '../Classes' for correct relative path resolution

This fixes Swift Package Manager detection for all ML Kit plugins.

* fix: correct Swift Package Manager package reference name

Swift Package Manager uses the URL-derived package name, not the @objc product name.
Changed all package references from 'GoogleMLKitSwiftPM' to 'google-mlkit-swiftpm'.

Also fixed GenAI packages (empty dependencies) to have valid SPM format.
@fbernaly

fbernaly commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

@arrrrny: I forgot to ask if you test this with the example app and ran on an actual device?

I ran the code and got multiple errors:

All plugins found for ios are Swift Packages, but your project still has CocoaPods integration. Your project uses a non-standard Podfile and will need to be migrated to Swift Package Manager manually. Some steps you may need to complete include:
  * In the ios/ directory run "pod deintegrate"
  * Transition any Pod dependencies to Swift Package equivalents. See https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app
  * Transition any custom logic
  * Remove the include to "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" in your ios/Flutter/Debug.xcconfig
  * Remove the include to "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" in your ios/Flutter/Release.xcconfig

Removing CocoaPods integration will improve the project's build time.
Launching lib/main.dart on fby’s iPhone in debug mode...
Error: Xcode failed to resolve Swift Package Manager dependencies:
2026-06-04 16:52:44.622 xcodebuild[32715:3828579] Writing error result bundle to /var/folders/8f/1hz5xkjs4z38c84z4j7yjmq80000gp/T/ResultBundle_2026-04-06_16-52-0044.xcresult
xcodebuild: error: Could not resolve package dependencies:
  target 'google_mlkit_barcode_scanning' in package 'google_mlkit_barcode_scanning' is outside the package root
  target 'google_mlkit_digital_ink_recognition' in package 'google_mlkit_digital_ink_recognition' is outside the package root
  target 'google_mlkit_document_scanner' in package 'google_mlkit_document_scanner' is outside the package root
  target 'google_mlkit_entity_extraction' in package 'google_mlkit_entity_extraction' is outside the package root
  target 'google_mlkit_face_detection' in package 'google_mlkit_face_detection' is outside the package root
  target 'google_mlkit_face_mesh_detection' in package 'google_mlkit_face_mesh_detection' is outside the package root
  target 'google_mlkit_genai_image_description' in package 'google_mlkit_genai_image_description' is outside the package root
  target 'google_mlkit_genai_prompt' in package 'google_mlkit_genai_prompt' is outside the package root
  target 'google_mlkit_genai_proofreading' in package 'google_mlkit_genai_proofreading' is outside the package root
  target 'google_mlkit_genai_rewriting' in package 'google_mlkit_genai_rewriting' is outside the package root
  target 'google_mlkit_genai_speech_recognition' in package 'google_mlkit_genai_speech_recognition' is outside the package root
  target 'google_mlkit_genai_summarization' in package 'google_mlkit_genai_summarization' is outside the package root
  target 'google_mlkit_image_labeling' in package 'google_mlkit_image_labeling' is outside the package root
  target 'google_mlkit_language_id' in package 'google_mlkit_language_id' is outside the package root
  target 'google_mlkit_object_detection' in package 'google_mlkit_object_detection' is outside the package root
  target 'google_mlkit_pose_detection' in package 'google_mlkit_pose_detection' is outside the package root
  target 'google_mlkit_selfie_segmentation' in package 'google_mlkit_selfie_segmentation' is outside the package root
  target 'google_mlkit_smart_reply' in package 'google_mlkit_smart_reply' is outside the package root
  target 'google_mlkit_subject_segmentation' in package 'google_mlkit_subject_segmentation' is outside the package root
  target 'google_mlkit_text_recognition' in package 'google_mlkit_text_recognition' is outside the package root
  target 'google_mlkit_commons' in package 'google_mlkit_commons' is outside the package root
  target 'google_mlkit_translation' in package 'google_mlkit_translation' is outside the package root
2


Exited (1).

I reverted the change and move it to the feature/spm branch. Branch it off and resubmit a PR showing evidence that it is running with no issues on an actual device.

@techwithsam

Copy link
Copy Markdown

@arrrrny can you look into the last report when you're chanced. Thanks

@arrrrny

arrrrny commented Jun 9, 2026

Copy link
Copy Markdown
Author

@fbernaly #874 addresses the issues

@techwithsam

Copy link
Copy Markdown

@fbernaly #874 addresses the issues

Awesome. @fbernaly can you check #874 to confirm this PR?

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.

4 participants