DartCvIOS library not compatible with iOS Simulator on Apple Silicon Macs
When building a Flutter app using opencv_dart 1.4.3 for iOS Simulator on an Apple Silicon Mac, the build fails because the DartCvIOS dependency provides an OpenCV library (libopencv.a) that is built for physical iOS devices rather than iOS simulators. This prevents testing the app on simulators on Apple Silicon Macs.
To Reproduce Steps to reproduce the behavior:
- Set up a Flutter project on an Apple Silicon Mac (M1/M2/M3)
- Add opencv_dart: ^1.4.3 to pubspec.yaml
- Run flutter pub get
- Attempt to build for iOS Simulator with arm64 architecture: flutter run -d "iPhone 16"
- See error:
Error (Xcode): Building for 'iOS-simulator', but linking in object file (/path/to/ios/Pods/DartCvIOS/libopencv/libopencv.a[arm64]21) built for 'iOS'
Expected behavior The app should build successfully for iOS Simulator on Apple Silicon Macs and launch without errors. The DartCvIOS library should provide OpenCV binaries that are compatible with both:
- iOS simulators (arm64 for Apple Silicon, x86_64 for Intel Macs)
- Physical iOS devices (arm64)
Desktop (please complete the following information):
- OS: macOS 14.5 (Darwin 23.5.0)
- Architecture: Apple Silicon (arm64)
- Xcode: 16.2 (Build version 16C5032a)
- Flutter: 3.38.1
- Dart: 3.10.0
Smartphone (please complete the following information):
- Simulator: iPhone 16 (iOS 18.3)
- Target: iOS Simulator on Apple Silicon Mac
- Expected Architecture: arm64 for simulator
Additional context
- The opencv_dart changelog mentions Apple Silicon support was added in v0.6.3 and universal iOS framework support in v1.0.6
- The issue persists even after:
- Upgrading from opencv_dart 1.0.4 to 1.4.3
- Modifying Podfile to override EXCLUDED_ARCHS[sdk=iphonesimulator*]
- Running flutter clean and rebuilding
- The app builds successfully (Xcode build succeeds), but the final binary contains device-only libraries
- The same app would likely work fine on a physical iOS device, but simulator testing is currently blocked
- Examining the built binary with codesign -dv confirms it's built for x86_64, not arm64
- The error specifically references /ios/Pods/DartCvIOS/libopencv/libopencv.a as being built for 'iOS' (device) rather than 'iOS-simulator'
Workaround Currently, the only workaround is to test on a physical iOS device instead of the simulator.
@Raghbinho Hi.
It's strange since I have just tested it by creating a new demo project and it works as expected, arm64 simulator should be excluded in both dartcvios.podspec (https://github.com/rainyl/dartcv/blob/0f1bcfff7f5caf9d0ea4d3b997b2f4639cc6c667/DartCvIOS.podspec#L41) and opencv_dart.podspec (https://github.com/rainyl/opencv_dart/blob/dc681b8dbf1c00492dfbccb10c3e2a9645d8df3c/packages/opencv_dart/ios/opencv_dart.podspec#L36).
The static library libopencv.a is a fat library built for arm64 and simulator-x64, since package arm64 and simulator-arm64 is not allowed, using a xcframework may works but I have no more time to do it and the best practice is using Native-Assets (now called hooks), I noticed that you are using dart 3.10 that supports hooks, you can try to use https://pub.dev/packages/dartcv4/versions/2.1.0-dev.2 and I will publish a stable version recently.
So, for now I am really don't know why, please create a fresh project, add opencv_dart and try whether it works.