Skip to content

Feat: add Swift Package Manager (SPM) support for all iOS packages#872

Closed
arrrrny wants to merge 6 commits into
flutter-ml:developfrom
arrrrny:pr/spm-all-packages
Closed

Feat: add Swift Package Manager (SPM) support for all iOS packages#872
arrrrny wants to merge 6 commits into
flutter-ml:developfrom
arrrrny:pr/spm-all-packages

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:

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
  • google_mlkit_pose_detection: MLKitPoseDetection, MLKitPoseDetectionAccurate
  • google_mlkit_commons: MLKitVision, MLImage, Common (base package)

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

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

lucasdonordeste and others added 6 commits May 8, 2026 23:41
Apple removed Rosetta 2 from the default iOS 26 simulator runtime, which
breaks `flutter run` for any project depending on Google ML Kit on
Apple Silicon Macs. The published GoogleMLKit/* CocoaPods only ship
arm64-iphoneos and x86_64-iphonesimulator slices and pin
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64, so the simulator build
no longer finds a matching destination and dies with
"Unable to find a destination matching the provided destination specifier".

Until Google publishes proper arm64-iphonesimulator slices
(https://issuetracker.google.com/issues/178965151), this change ships an
opt-in Podfile helper under google_mlkit_commons that:

1. Re-labels the existing arm64 device slice of every ML Kit framework
   binary as iOS Simulator. Only the 4-byte LC_BUILD_VERSION.platform
   field is changed (2 -> 7), the same approach the well-known
   arm64-to-sim tool uses on closed-source SDKs. Idempotent.
2. Strips EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 from the
   xcconfigs CocoaPods generates from the pod's user_target_xcconfig,
   so the user's app target is allowed to build for arm64-iphonesimulator.

The example/ios Podfile is wired to call the helper from post_install,
which lets the example app build, install and run on an Apple Silicon
iOS 26.3 simulator. End-to-end validated: Text Recognition on the
Text-From-Widget view returned the exact widget text. Device builds and
release builds are not affected.

Closes flutter-ml#825
The Ruby and Python entry points already have a brief header pointing at
the README. Per-function docstrings were restating what the function name
already said, and the Podfile inline comments duplicated the helper's
self-documenting name.
- Add Ruby helper script for Podfile integration
- Add Python script to re-label arm64 device slices as iOS Simulator
- Update example Podfile to use the opt-in helper
- Document the solution in google_mlkit_commons/README.md

This enables Google ML Kit to build on Apple Silicon iOS 26+ simulators
where Rosetta 2 is no longer the default. Fixes Google internal issue #178965151.
Add Package.swift files for:
- google_mlkit_commons: MLKitVision, MLImage, Common dependencies
- google_mlkit_pose_detection: MLKitPoseDetection, MLKitPoseDetectionCommon, MLKitVision, MLImage, Common dependencies

This resolves the Swift Package Manager migration warning and prepares
the plugins for future Flutter versions that will require SPM support.
Uses 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 closed this Jun 4, 2026
@arrrrny arrrrny deleted the pr/spm-all-packages branch June 4, 2026 05:48
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.

2 participants