This is experimental project for building MLKit in Swift Package Manager.
New: This repository now includes automated tools to keep up-to-date with MLKit releases. See AUTOMATION.md for details.
- iOS 14 and later
- Xcode 13.2.1 and later
Add the package dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/d-date/google-mlkit-swiftpm", from: "9.0.0")
]Then add the specific ML Kit modules you need to your target dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "MLKitBarcodeScanning", package: "google-mlkit-swiftpm"),
.product(name: "MLKitFaceDetection", package: "google-mlkit-swiftpm"),
.product(name: "MLKitTextRecognition", package: "google-mlkit-swiftpm"),
.product(name: "MLKitImageLabeling", package: "google-mlkit-swiftpm"),
.product(name: "MLKitObjectDetection", package: "google-mlkit-swiftpm"),
.product(name: "MLKitPoseDetection", package: "google-mlkit-swiftpm"),
.product(name: "MLKitSegmentationSelfie", package: "google-mlkit-swiftpm"),
.product(name: "MLKitLanguageID", package: "google-mlkit-swiftpm"),
.product(name: "MLKitTranslate", package: "google-mlkit-swiftpm"),
.product(name: "MLKitSmartReply", package: "google-mlkit-swiftpm"),
]
)Add these flags to Other Linker Flags in Build Settings of your Xcode projects.
-ObjC-all_load
Some ML Kit modules require resource bundles. Currently:
The MLKitFaceDetection module requires GoogleMVFaceDetectorResources.bundle. Since bundles can't be automatically included via Swift Package Manager, you need to manually add it to your project.
Download GoogleMVFaceDetectorResources.bundle from Release and add it to your Xcode project, ensuring it's included in your build target.
Note: Other modules (Text Recognition, Pose Detection, Object Detection, Selfie Segmentation, Translation) may also require resource bundles or downloaded models at runtime. Check the official ML Kit documentation for specific requirements.
This package supports the following Google ML Kit features:
- Barcode Scanning - Scan and decode barcodes
- Face Detection - Detect faces and facial features
- Text Recognition - Recognize text in images (v2)
- Image Labeling - Identify objects, locations, activities, and more
- Object Detection & Tracking - Detect and track objects in images and video
- Pose Detection - Detect body poses and positions
- Selfie Segmentation - Segment people from the background
- Language Identification - Identify the language of text
- Translation - Translate text between languages
- Smart Reply - Generate contextual reply suggestions
- Since pre-built MLKit binary missing
arm64for iphonesimulator, this project enables to build inarm64for iphoneos andx86_64for iphonesimulator only.
Open Example/Example.xcworkspace and fixing code signing to yours.
This repository includes automation tools for updating to new MLKit versions:
- Automated Version Checking: Daily checks for new MLKit releases
- Build Automation: Scripts to build and package new versions
- GitHub Actions: Workflows for automated builds and releases
For detailed information, see AUTOMATION.md.
To update to a new MLKit version:
# Check for updates
ruby scripts/check_mlkit_version.rb
# Build new version (replace 5.1.0 with actual version)
./scripts/build_all.sh 5.1.0Or use the GitHub Actions workflow for fully automated builds.