Skip to content

fix: SPM migration - fix Package.swift product refs, pod deintegrate,…#874

Merged
fbernaly merged 10 commits into
flutter-ml:developfrom
arrrrny:spm-fixed
Jun 13, 2026
Merged

fix: SPM migration - fix Package.swift product refs, pod deintegrate,…#874
fbernaly merged 10 commits into
flutter-ml:developfrom
arrrrny:spm-fixed

Conversation

@arrrrny

@arrrrny arrrrny commented Jun 9, 2026

Copy link
Copy Markdown

… update gitignore

@arrrrny

arrrrny commented Jun 9, 2026

Copy link
Copy Markdown
Author

built example ios app, it works.

@arrrrny

arrrrny commented Jun 9, 2026

Copy link
Copy Markdown
Author
~/D/z/p/example ❯❯❯ flutter run
Resolving dependencies...
Downloading packages...
  async 2.13.0 (2.13.1 available)
  camera 0.11.3 (0.12.0+1 available)
  camera_android 0.10.10+14 (0.10.10+18 available)
  camera_android_camerax 0.6.30 (0.7.2+1 available)
  camera_avfoundation 0.9.22+9 (0.10.1 available)
  camera_platform_interface 2.12.0 (2.13.0 available)
  ffi 2.1.5 (2.2.0 available)
  flutter_plugin_android_lifecycle 2.0.33 (2.0.35 available)
! google_mlkit_commons 0.11.1 from path ../google_mlkit_commons (overridden)
  image_picker 1.2.1 (1.2.2 available)
  image_picker_android 0.8.13+13 (0.8.13+19 available)
  image_picker_ios 0.8.13+3 (0.8.13+6 available)
  matcher 0.12.19 (0.12.20 available)
  meta 1.18.0 (1.18.3 available)
  path_provider_android 2.2.22 (2.3.1 available)
  path_provider_foundation 2.5.1 (2.6.0 available)
  source_span 1.10.1 (1.10.2 available)
  test_api 0.7.11 (0.7.12 available)
  vector_math 2.2.0 (2.4.0 available)
  vm_service 15.0.2 (15.2.0 available)
Got dependencies!
19 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Launching lib/main.dart on ARRRRNY in debug mode...
Xcode is fetching Swift Package Manager dependencies. This may take
several minutes...
  Fetching from https://github.com/firebase/nanopb.git (cached)...
  Fetching from https://github.com/google/gtm-session-fetcher.git (cached)...
  Fetching from https://github.com/d-date/google-mlkit-swiftpm (cached)...
  Fetching from https://github.com/google/GoogleUtilities.git (cached)...
  Fetching from https://github.com/google/promises.git (cached)...
  Fetching from https://github.com/google/GoogleDataTransport.git (cached)...
Found saved certificate choice "Apple Development: Ahmet Tok
(J82RRB32HT)". To clear, use "flutter config
--clear-ios-signing-settings".
Developer identity "Apple Development: Ahmet Tok (J82RRB32HT)"
selected for iOS code signing
Running Xcode build...
Xcode build done.                                           186.2s
Installing and launching...                                              40.6s
Syncing files to device ARRRRNY...                                       263ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

@fbernaly

fbernaly commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

@arrrrny :
image

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 continues the iOS Swift Package Manager (SPM) migration across the google_mlkit_* Flutter plugins by introducing Package.swift manifests and SPM-friendly Swift sources, updating shared iOS utilities in google_mlkit_commons, and deintegrating CocoaPods from the example iOS app.

Changes:

  • Add SwiftPM Package.swift manifests (and SPM Sources/ implementations) for multiple iOS plugin packages.
  • Introduce/port shared iOS Swift utilities in google_mlkit_commons (e.g., VisionImage creation + a generic model manager).
  • Migrate the example iOS app away from CocoaPods (remove Podfile/Podfile.lock references, add SwiftPM resolved state) and update .gitignore for SwiftPM artifacts.

Reviewed changes

Copilot reviewed 42 out of 67 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
packages/google_mlkit_translation/ios/google_mlkit_translation/Sources/google_mlkit_translation/GoogleMlKitTranslationPlugin.swift Adds SPM Sources/ implementation for Translation plugin.
packages/google_mlkit_translation/ios/google_mlkit_translation/Package.swift Adds SwiftPM manifest for Translation plugin.
packages/google_mlkit_translation/ios/google_mlkit_translation/Classes/GoogleMlKitTranslationPlugin.swift Keeps CocoaPods Classes/ implementation for Translation plugin.
packages/google_mlkit_text_recognition/ios/google_mlkit_text_recognition/Sources/google_mlkit_text_recognition/GoogleMlKitTextRecognitionPlugin.swift Adds SPM Sources/ implementation for Text Recognition plugin.
packages/google_mlkit_text_recognition/ios/google_mlkit_text_recognition/Package.swift Adds SwiftPM manifest for Text Recognition plugin.
packages/google_mlkit_text_recognition/ios/google_mlkit_text_recognition/Classes/GoogleMlKitTextRecognitionPlugin.swift Keeps CocoaPods Classes/ implementation for Text Recognition plugin.
packages/google_mlkit_subject_segmentation/ios/google_mlkit_subject_segmentation/Sources/google_mlkit_subject_segmentation/GoogleMlKitSubjectSegmentationPlugin.swift Adds SPM Sources/ stub implementation for Subject Segmentation plugin.
packages/google_mlkit_subject_segmentation/ios/google_mlkit_subject_segmentation/Package.swift Adds SwiftPM manifest for Subject Segmentation plugin.
packages/google_mlkit_smart_reply/ios/google_mlkit_smart_reply/Sources/google_mlkit_smart_reply/GoogleMlKitSmartReplyPlugin.swift Adds SPM Sources/ implementation for Smart Reply plugin.
packages/google_mlkit_smart_reply/ios/google_mlkit_smart_reply/Package.swift Adds SwiftPM manifest for Smart Reply plugin.
packages/google_mlkit_smart_reply/ios/google_mlkit_smart_reply/Classes/GoogleMlKitSmartReplyPlugin.swift Keeps CocoaPods Classes/ implementation for Smart Reply plugin.
packages/google_mlkit_selfie_segmentation/ios/google_mlkit_selfie_segmentation/Sources/google_mlkit_selfie_segmentation/GoogleMlKitSelfieSegmentationPlugin.swift Adds SPM Sources/ implementation for Selfie Segmentation plugin.
packages/google_mlkit_selfie_segmentation/ios/google_mlkit_selfie_segmentation/Package.swift Adds SwiftPM manifest for Selfie Segmentation plugin.
packages/google_mlkit_selfie_segmentation/ios/google_mlkit_selfie_segmentation/Classes/GoogleMlKitSelfieSegmentationPlugin.swift Keeps CocoaPods Classes/ implementation for Selfie Segmentation plugin.
packages/google_mlkit_pose_detection/ios/google_mlkit_pose_detection/Sources/google_mlkit_pose_detection/GoogleMlKitPoseDetectionPlugin.swift Adds SPM Sources/ implementation for Pose Detection plugin.
packages/google_mlkit_pose_detection/ios/google_mlkit_pose_detection/Package.swift Adds SwiftPM manifest for Pose Detection plugin.
packages/google_mlkit_pose_detection/ios/google_mlkit_pose_detection/Classes/GoogleMlKitPoseDetectionPlugin.swift Keeps CocoaPods Classes/ implementation for Pose Detection plugin.
packages/google_mlkit_object_detection/ios/google_mlkit_object_detection/Sources/google_mlkit_object_detection/GoogleMlKitObjectDetectionPlugin.swift Adds SPM Sources/ implementation for Object Detection plugin.
packages/google_mlkit_object_detection/ios/google_mlkit_object_detection/Package.swift Adds SwiftPM manifest for Object Detection plugin.
packages/google_mlkit_object_detection/ios/google_mlkit_object_detection/Classes/GoogleMlKitObjectDetectionPlugin.swift Keeps CocoaPods Classes/ implementation for Object Detection plugin.
packages/google_mlkit_language_id/ios/google_mlkit_language_id/Sources/google_mlkit_language_id/GoogleMlKitLanguageIdPlugin.swift Adds SPM Sources/ implementation for Language ID plugin.
packages/google_mlkit_language_id/ios/google_mlkit_language_id/Package.swift Adds SwiftPM manifest for Language ID plugin.
packages/google_mlkit_language_id/ios/google_mlkit_language_id/Classes/GoogleMlKitLanguageIdPlugin.swift Keeps CocoaPods Classes/ implementation for Language ID plugin.
packages/google_mlkit_image_labeling/ios/google_mlkit_image_labeling/Sources/google_mlkit_image_labeling/GoogleMlKitImageLabelingPlugin.swift Adds SPM Sources/ implementation for Image Labeling plugin.
packages/google_mlkit_image_labeling/ios/google_mlkit_image_labeling/Package.swift Adds SwiftPM manifest for Image Labeling plugin.
packages/google_mlkit_image_labeling/ios/google_mlkit_image_labeling/Classes/GoogleMlKitImageLabelingPlugin.swift Keeps CocoaPods Classes/ implementation for Image Labeling plugin.
packages/google_mlkit_genai_summarization/ios/google_mlkit_genai_summarization/Sources/google_mlkit_genai_summarization/GoogleMlKitGenaiSummarizationPlugin.swift Adds iOS stub implementation for GenAI Summarization plugin.
packages/google_mlkit_genai_summarization/ios/google_mlkit_genai_summarization/Package.swift Adds SwiftPM manifest for GenAI Summarization plugin.
packages/google_mlkit_genai_speech_recognition/ios/google_mlkit_genai_speech_recognition/Sources/google_mlkit_genai_speech_recognition/GoogleMlKitGenaiSpeechRecognitionPlugin.swift Adds iOS stub implementation for GenAI Speech Recognition plugin.
packages/google_mlkit_genai_speech_recognition/ios/google_mlkit_genai_speech_recognition/Package.swift Adds SwiftPM manifest for GenAI Speech Recognition plugin.
packages/google_mlkit_genai_rewriting/ios/google_mlkit_genai_rewriting/Sources/google_mlkit_genai_rewriting/GoogleMlKitGenaiRewritingPlugin.swift Adds iOS stub implementation for GenAI Rewriting plugin.
packages/google_mlkit_genai_rewriting/ios/google_mlkit_genai_rewriting/Package.swift Adds SwiftPM manifest for GenAI Rewriting plugin.
packages/google_mlkit_genai_proofreading/ios/google_mlkit_genai_proofreading/Sources/google_mlkit_genai_proofreading/GoogleMlKitGenaiProofreadingPlugin.swift Adds iOS stub implementation for GenAI Proofreading plugin.
packages/google_mlkit_genai_proofreading/ios/google_mlkit_genai_proofreading/Package.swift Adds SwiftPM manifest for GenAI Proofreading plugin.
packages/google_mlkit_genai_prompt/ios/google_mlkit_genai_prompt/Sources/google_mlkit_genai_prompt/GoogleMlKitGenaiPromptPlugin.swift Adds iOS stub implementation for GenAI Prompt plugin.
packages/google_mlkit_genai_prompt/ios/google_mlkit_genai_prompt/Package.swift Adds SwiftPM manifest for GenAI Prompt plugin.
packages/google_mlkit_genai_image_description/ios/google_mlkit_genai_image_description/Sources/google_mlkit_genai_image_description/GoogleMlKitGenaiImageDescriptionPlugin.swift Adds iOS stub implementation for GenAI Image Description plugin.
packages/google_mlkit_genai_image_description/ios/google_mlkit_genai_image_description/Package.swift Adds SwiftPM manifest for GenAI Image Description plugin.
packages/google_mlkit_face_mesh_detection/ios/google_mlkit_face_mesh_detection/Sources/google_mlkit_face_mesh_detection/GoogleMlKitFaceMeshDetectionPlugin.swift Adds iOS stub implementation for Face Mesh Detection plugin.
packages/google_mlkit_face_mesh_detection/ios/google_mlkit_face_mesh_detection/Package.swift Adds SwiftPM manifest for Face Mesh Detection plugin.
packages/google_mlkit_face_detection/ios/google_mlkit_face_detection/Sources/google_mlkit_face_detection/GoogleMlKitFaceDetectionPlugin.swift Adds SPM Sources/ implementation for Face Detection plugin.
packages/google_mlkit_face_detection/ios/google_mlkit_face_detection/Package.swift Adds SwiftPM manifest for Face Detection plugin.
packages/google_mlkit_entity_extraction/ios/google_mlkit_entity_extraction/Sources/google_mlkit_entity_extraction/GoogleMlKitEntityExtractionPlugin.swift Adds SPM Sources/ implementation + SPM-availability gating for Entity Extraction.
packages/google_mlkit_entity_extraction/ios/google_mlkit_entity_extraction/Package.swift Adds SwiftPM manifest for Entity Extraction plugin.
packages/google_mlkit_entity_extraction/ios/Classes/GoogleMlKitEntityExtractionPlugin.swift Removes the prior CocoaPods-only implementation file.
packages/google_mlkit_document_scanner/ios/google_mlkit_document_scanner/Sources/google_mlkit_document_scanner/GoogleMlKitDocumentScannerPlugin.swift Adds SPM Sources/ implementation for Document Scanner plugin.
packages/google_mlkit_document_scanner/ios/google_mlkit_document_scanner/Package.swift Adds SwiftPM manifest for Document Scanner plugin.
packages/google_mlkit_digital_ink_recognition/ios/google_mlkit_digital_ink_recognition/Sources/google_mlkit_digital_ink_recognition/GoogleMlKitDigitalInkRecognitionPlugin.swift Adds SPM Sources/ implementation + SPM-availability gating for Digital Ink Recognition.
packages/google_mlkit_digital_ink_recognition/ios/google_mlkit_digital_ink_recognition/Package.swift Adds SwiftPM manifest for Digital Ink Recognition plugin.
packages/google_mlkit_digital_ink_recognition/ios/Classes/GoogleMlKitDigitalInkRecognitionPlugin.swift Removes the prior CocoaPods-only implementation file.
packages/google_mlkit_commons/ios/google_mlkit_commons/Sources/google_mlkit_commons/MLKVisionImage+FlutterPlugin.swift Adds Swift VisionImage factory from Flutter image data.
packages/google_mlkit_commons/ios/google_mlkit_commons/Sources/google_mlkit_commons/GoogleMlKitCommonsPlugin.swift Adds SPM Sources/ plugin registrar stub for commons.
packages/google_mlkit_commons/ios/google_mlkit_commons/Sources/google_mlkit_commons/GenericModelManager.swift Adds a shared model manager helper for download/delete/check flows.
packages/google_mlkit_commons/ios/google_mlkit_commons/Package.swift Adds SwiftPM manifest for commons package.
packages/google_mlkit_commons/ios/google_mlkit_commons/Package.resolved Pins SwiftPM dependencies for commons.
packages/google_mlkit_barcode_scanning/ios/google_mlkit_barcode_scanning/Sources/google_mlkit_barcode_scanning/GoogleMlKitBarcodeScanningPlugin.swift Adds SPM Sources/ implementation for Barcode Scanning plugin.
packages/google_mlkit_barcode_scanning/ios/google_mlkit_barcode_scanning/Package.swift Adds SwiftPM manifest for Barcode Scanning plugin.
packages/example/pubspec.lock Updates Dart/Flutter dependencies lockfile.
packages/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved Adds SwiftPM resolved state for the example app workspace.
packages/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Adds SwiftPM resolved state for the example app project workspace.
packages/example/ios/Runner.xcodeproj/project.pbxproj Removes CocoaPods artifacts from Xcode project and adjusts settings for SPM.
packages/example/ios/Podfile.lock Removes CocoaPods lockfile from example app.
packages/example/ios/Podfile Removes CocoaPods Podfile from example app.
packages/example/ios/Flutter/Release.xcconfig Removes CocoaPods xcconfig include for Release.
packages/example/ios/Flutter/Profile.xcconfig Removes CocoaPods xcconfig include for Profile.
packages/example/ios/Flutter/Debug.xcconfig Removes CocoaPods xcconfig include for Debug.
.gitignore Ignores SwiftPM build metadata directories.

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

Comment thread packages/google_mlkit_translation/ios/google_mlkit_translation/Package.swift Outdated
Comment thread packages/google_mlkit_smart_reply/ios/google_mlkit_smart_reply/Package.swift Outdated
@fbernaly

fbernaly commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

@arrrrny : Address the Copilot comments

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

Copilot reviewed 42 out of 67 changed files in this pull request and generated 4 comments.

Comment thread packages/google_mlkit_commons/ios/google_mlkit_commons/Package.swift Outdated
@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny : take a look at the new comments ^^

@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny :
image

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

Copilot reviewed 64 out of 89 changed files in this pull request and generated 1 comment.

@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny : There are some hidden comments that need to be addressed as well:

image

@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny : thanks for bearing with me and working on all of this changes.

@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny : could you mark as resolved all the comments, even the hidden ones?

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

Copilot reviewed 64 out of 89 changed files in this pull request and generated 13 comments.

@fbernaly fbernaly merged commit 41e2731 into flutter-ml:develop Jun 13, 2026
2 checks passed
@fbernaly

Copy link
Copy Markdown
Collaborator

@arrrrny : Did you run this code on an actual device?

I merged the code and tested on a device. I tried doing face detection and barcode scanning and it is crashing at run time:

Launching lib/main.dart on fby’s iPhone in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project:
Running Xcode build...
Xcode build done.                                           31.3s
Installing and launching...
Debug service listening on ws://127.0.0.1:61920/lvCZzz6QQfg=/ws
Syncing files to device fby’s iPhone...
INFO: Initialized TensorFlow Lite runtime.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
*** First throw call stack:
(0x1a26ce23c 0x19f19d224 0x1a273f054 0x1a261c52c 0x1a2626e60 0x118f76f88 0x118f76c60 0x118f761f0 0x118f75c04 0x1dc9db9a8 0x1dc9f51e4 0x1dc9e3fb0 0x1dc9e4aac 0x1dc9eedac 0x1dc9ee6ac 0x2017ad3b0 0x2017ac8c0)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[MLKITx_GMVUtility grayPixelData:orientation:width:height:]: unrecognized selector sent to class 0x11b5584a0'
*** First throw call stack:
(0x1a26ce23c 0x19f19d224 0x1a273f054 0x1a261c52c 0x1a2626e60 0x118f76f88 0x118f76c60 0x118f761f0 0x118f75c04 0x1dc9db9a8 0x1dc9f51e4 0x1dc9e3fb0 0x1dc9e4aac 0x1dc9eedac 0x1dc9ee6ac 0x2017ad3b0 0x2017ac8c0)
libc++abi: terminating due to uncaught exception of type NSException
Process 671 resuming
Process 671 stopped
* thread #2, queue = 'com.google.mlkit.barcodescanning', stop reason = signal SIGABRT
    frame #0: 0x00000002513771d0 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x2513771d0 <+8>:  b.lo   0x2513771f0               ; <+40>
    0x2513771d4 <+12>: pacibsp 
    0x2513771d8 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x2513771dc <+20>: mov    x29, sp
Target 0: (Runner) stopped.

Because of that this PR has been reverted and move to a feature branch.
Please test on a device and submit proof of running the detection, not only proof of building. This crash is at runtime.

@fbernaly

Copy link
Copy Markdown
Collaborator

this is the branch if you want to give it a try:
https://github.com/flutter-ml/google_ml_kit_flutter/tree/feature/spm_v2

@arrrrny

arrrrny commented Jun 13, 2026

Copy link
Copy Markdown
Author

Quick status update:

✅ Barcode scanning — tested and working on device with 9.0.0-1.

❌ Text Recognition, Object Detection, Pose Detection, Selfie Segmentation — all fail at runtime because google-mlkit-swiftpm packages these as Mach-O object files where model data is compiled as C++ data. SPM strips these data sections when building the framework dylib, leaving thin wrappers without model data.

I've filed an upstream issue with a detailed explanation of the root cause and suggested fix: d-date/google-mlkit-swiftpm#106

Face Detection and Image Labeling should also work (they have separate .bundle resources like barcode scanning does), but those need device testing to confirm.

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.

3 participants