Skip to content

Commit 5bde8cd

Browse files
committed
feat: add Swift Package Manager (SPM) support for iOS
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 #868
1 parent 3cd46c1 commit 5bde8cd

3 files changed

Lines changed: 109 additions & 0 deletions

File tree

packages/google_mlkit_commons/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ end
7777

7878
Notice that the minimum `IPHONEOS_DEPLOYMENT_TARGET` is 15.5, you can set it to something newer but not older.
7979

80+
#### Apple Silicon iOS Simulator (iOS 26+)
81+
82+
Google's `GoogleMLKit/*` pods only ship `arm64-iphoneos` and `x86_64-iphonesimulator` slices and exclude `arm64` from simulator builds. On Apple Silicon Macs running iOS 26+ simulators (where Rosetta 2 is no longer the default for the iOS Simulator) this makes `flutter run` fail with `Unable to find a destination matching the provided destination specifier`. Issue tracked upstream by Google: https://issuetracker.google.com/issues/178965151.
83+
84+
Until proper `arm64-iphonesimulator` slices are published, this plugin ships an **opt-in** Podfile helper that re-labels the existing arm64 device slice as iOS Simulator (the same `LC_BUILD_VERSION.platform` swap used by the well-known [`arm64-to-sim`](https://github.com/bogo/arm64-to-sim) tool) and strips the `EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64` from the generated xcconfigs.
85+
86+
To enable it, add two lines to your iOS `Podfile`:
87+
88+
```ruby
89+
# Near the top, after `require ... podhelper ...`:
90+
require File.expand_path(
91+
'.symlinks/plugins/google_mlkit_commons/ios/scripts/apple_silicon_simulator',
92+
__dir__,
93+
)
94+
95+
post_install do |installer|
96+
# ...your existing post_install code...
97+
98+
# Add this line at the end:
99+
mlkit_apple_silicon_simulator_patch(installer)
100+
end
101+
```
102+
103+
Then re-run `pod install`. The example app under `packages/example` is wired up this way.
104+
105+
The helper only changes vendored binaries inside `Pods/` and the `EXCLUDED_ARCHS` line in pod-generated xcconfigs. Device builds and release builds are unaffected. Remove the two lines to revert.
106+
107+
#### Swift Package Manager (SPM) Support
108+
109+
This plugin supports Swift Package Manager for iOS, which is the recommended way to manage iOS dependencies in Flutter 3.44+. CocoaPods support is deprecated and will be removed in future Flutter versions.
110+
111+
No additional configuration is needed - Flutter will automatically detect and use the `Package.swift` file when building for iOS. The plugin uses the community-maintained [d-date/google-mlkit-swiftpm](https://github.com/d-date/google-mlkit-swiftpm) package for ML Kit binary dependencies.
112+
113+
For more information, see: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
114+
80115
### Android
81116

82117
- minSdkVersion: 21
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// swift-tools-version:5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
// This Package.swift provides Swift Package Manager support for google_mlkit_commons.
5+
// See: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
6+
7+
import PackageDescription
8+
9+
let package = Package(
10+
name: "google_mlkit_commons",
11+
platforms: [
12+
.iOS("15.5")
13+
],
14+
products: [
15+
.library(
16+
name: "google_mlkit_commons",
17+
targets: ["google_mlkit_commons"])
18+
],
19+
dependencies: [
20+
.package(
21+
url: "https://github.com/d-date/google-mlkit-swiftpm",
22+
from: "9.0.0"
23+
)
24+
],
25+
targets: [
26+
.target(
27+
name: "google_mlkit_commons",
28+
dependencies: [
29+
.product(name: "MLKitVision", package: "GoogleMLKitSwiftPM"),
30+
.product(name: "MLImage", package: "GoogleMLKitSwiftPM"),
31+
.product(name: "Common", package: "GoogleMLKitSwiftPM"),
32+
],
33+
path: "Classes"
34+
)
35+
]
36+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-tools-version:5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
// This Package.swift provides Swift Package Manager support for google_mlkit_pose_detection.
5+
// See: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors
6+
7+
import PackageDescription
8+
9+
let package = Package(
10+
name: "google_mlkit_pose_detection",
11+
platforms: [
12+
.iOS("15.5")
13+
],
14+
products: [
15+
.library(
16+
name: "google_mlkit_pose_detection",
17+
targets: ["google_mlkit_pose_detection"])
18+
],
19+
dependencies: [
20+
.package(
21+
url: "https://github.com/d-date/google-mlkit-swiftpm",
22+
from: "9.0.0"
23+
)
24+
],
25+
targets: [
26+
.target(
27+
name: "google_mlkit_pose_detection",
28+
dependencies: [
29+
.product(name: "MLKitPoseDetection", package: "GoogleMLKitSwiftPM"),
30+
.product(name: "MLKitPoseDetectionCommon", package: "GoogleMLKitSwiftPM"),
31+
.product(name: "MLImage", package: "GoogleMLKitSwiftPM"),
32+
.product(name: "MLKitVision", package: "GoogleMLKitSwiftPM"),
33+
.product(name: "Common", package: "GoogleMLKitSwiftPM"),
34+
],
35+
path: "Classes"
36+
)
37+
]
38+
)

0 commit comments

Comments
 (0)