Skip to content

feat(ios): migrate 8 plugins to Swift Package Manager (SPM) #875#884

Open
vicajilau wants to merge 1 commit into
flutter-ml:developfrom
vicajilau:feat/spm-migration-875
Open

feat(ios): migrate 8 plugins to Swift Package Manager (SPM) #875#884
vicajilau wants to merge 1 commit into
flutter-ml:developfrom
vicajilau:feat/spm-migration-875

Conversation

@vicajilau

Copy link
Copy Markdown

Description

This PR adds Swift Package Manager (SPM) support to all the plugins in the monorepo that do not have external native dependencies on Google's ML Kit SDK, addressing the transition discussed in #875.

Since Google does not officially support Swift Package Manager for the native ML Kit SDK (it is only distributed via CocoaPods), any plugin depending on it is blocked from a full SPM migration. However, this PR implements a dual-package manager (hybrid) configuration, migrating the independent plugins while maintaining CocoaPods fallback support for the rest.


Migration Summary

1. Migrated Packages (8 Packages)

These plugins do not use the Google ML Kit iOS SDK (they are either GenAI plugins, unimplemented on iOS, or only return mock/stub values) and only depend on Flutter. They now have a Package.swift file and their source code structured under Sources/ for SwiftPM compatibility, while keeping their .podspec updated for CocoaPods:

  • google_mlkit_genai_prompt
  • google_mlkit_genai_rewriting
  • google_mlkit_genai_image_description
  • google_mlkit_genai_summarization
  • google_mlkit_genai_speech_recognition
  • google_mlkit_genai_proofreading
  • google_mlkit_document_scanner
  • google_mlkit_subject_segmentation

2. Blocked Packages - Remaining on CocoaPods (14 Packages)

The core shared package and all active ML Kit features depend directly on the CocoaPods-only Google ML Kit SDK frameworks (MLKitVision, MLKitFaceDetection, etc.). Since SwiftPM targets cannot link CocoaPods dependencies, these must remain on CocoaPods until Google officially publishes SPM wrappers:

  • google_mlkit_commons
  • google_mlkit_barcode_scanning
  • google_mlkit_digital_ink_recognition
  • google_mlkit_entity_extraction
  • google_mlkit_face_detection
  • google_mlkit_face_mesh_detection (depends on google_mlkit_commons)
  • google_mlkit_image_labeling
  • google_mlkit_language_id
  • google_mlkit_object_detection
  • google_mlkit_pose_detection
  • google_mlkit_selfie_segmentation
  • google_mlkit_smart_reply
  • google_mlkit_text_recognition
  • google_mlkit_translation

Changes Implemented

  • Directory Structure Refactoring: Moved iOS Swift source files from ios/Classes/ to ios/[plugin_name]/Sources/[plugin_name]/ in the 8 migrated packages.
  • SPM Configuration: Added Package.swift in the subdirectory of each migrated package, declaring target libraries (with dash-cased names like google-mlkit-genai-prompt matching Flutter's SPM workspace expectation).
  • CocoaPods Compatibility: Updated .podspec files to point to the new SPM source path so that legacy CocoaPods integrations continue to work seamlessly.
  • Gitignore: Ignored .build/ directories created by SPM.

Verification & Testing

Tested in packages/example on Flutter 3.44.5+ with SPM enabled:

  1. Enabled SwiftPM: flutter config --enable-swift-package-manager
  2. Cleared caches & resolved packages: flutter clean && flutter pub get
  3. Built successfully using a hybrid build (compiling SPM packages and linking Pods together):
    flutter build ios --no-codesign

@fbernaly

fbernaly commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

@vicajilau: There is already a branch with these changes: feature/spm. Please double-check if your changes are already included there. If they are, feel free to close #884. If not, please update #884 to target the feature/spm branch instead.
Also, for verification make sure the now just compile but those features run correctly. I have found that sometime that app compiles but there are runtime crashes.

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