tflite_flutter_plugin
tflite_flutter_plugin copied to clipboard
iOS simulator cannot be used
The build for simulator fails at link time:
ld: building for iOS Simulator, but linking in object file built for iOS, file '/Users/harri/flutter/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-0.9.0/ios/TensorFlowLiteC.framework/TensorFlowLiteC' for architecture arm64
Even if ML part would be suboptimal, the simulator use would be useful to test other parts of the app and to get screenshots.
Having the same issue!
Edit: downgrading back to Flutter 2.2.3 seemed to solve it for me. Considering that this bug was discovered at roughly the same time, I suspect it has something to do with the new version of Flutter, and tflite_flutter 0.8.0/0.9.0 being incompatible with it.
I have the same problem and I've resolved using these instructions.
The problem is because with the release of Xcode 12, $ARCHS_STANDARD includes arm64 for simulator builds, so you should add arm64
in EXCLUDED_ARCHS
setting, maintaining original setting i386
. Unfortunately, this doesn't work in Debug.xcconfig
: you should set it instead in your Podfile
adding this build configuration setting:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386 arm64'
end
end
end
I have tried almost everything here but I am still unable to get my app working with iOS simulator. I am stuck on TensorFlowLiteC.framework error. I have MacBook M1 maybe that's the culprit. Any help would be much appreciated.
I have tried almost everything here but I am still unable to get my app working with iOS simulator. I am stuck on TensorFlowLiteC.framework error. I have MacBook M1 maybe that's the culprit. Any help would be much appreciated.
I got the same problem as @physxP. Also on m1, but cross checked my project on an intel Mac, same problem.
Also the path ~/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-<plugin-version>/ios/
did not exist, I had to create /tflite_flutter-<plugin-version>/iOS/
myself. Maybe that helps with analysing the problem.
@mantaBracket
I figured out the problem. When you build on Xcode error is shown while linking TensorflowLiteC.framework:
I fixed it by copying TensorFlowLiteC.framework into the directory where error is shown in Xcode (in the same directory where tflite_flutter.framework is situated). For me it was (as highlighted in the image): /Users/tj/Library/Developer/Xcode/DerivedData/Runner-ckdkwddwvtkqbwepmofwzmhkcaed/Build/Products/Debug-iphoneos/tflite_flutter
Before this step the build step was also failing for real iOS device so my issue could be something else.
Thanks a lot, building and running now works with this workaround when using Xcode. When using flutter run
in cli it still fails for iOS.
Thanks a lot @physxP it work!
THAT WORKS CHARMLY. THANK YOU THANK YOU THANK YOU
I have the same problem and I've resolved using these instructions. The problem is because with the release of Xcode 12, $ARCHS_STANDARD includes arm64 for simulator builds, so you should add
arm64
inEXCLUDED_ARCHS
setting, maintaining original settingi386
. Unfortunately, this doesn't work inDebug.xcconfig
: you should set it instead in yourPodfile
adding this build configuration setting:post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386 arm64' end end end
The @ricibald 'solution' disables c++ modules, so, this causes a chain effect of killing most other libraries that would be useful to have (like firebase).
So now we have to debug only on devices, or is there another solution for the arm64 library...can we somehow get an arm64 compatible TensorFlowLiteC lib from somewhere?
@klivin There's also a .pub-cache folder in the flutter install dir. The readme is telling us to copy the TensorflowLiteC in the home directory folder but if you also copy inside the flutter pub-cache then it might work. e.g. my flutter install dir is:
~/libs/flutter
so I should copy the TensorflowLiteC folder to :
~/libs/flutter/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-0.9.0/ios
@physxP Thanks for the reply. I've copied TensorflowLiteC to both the pub cache and derived data locations (ensuring the links in flutter are going to the correct cache location). See:
cd /Users/kevinw/Development/flutter/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-0.9.0/ios/TensorFlowLiteC.framework/
➜ TensorFlowLiteC.framework git:(stable) ✗ ls
Headers Modules TensorFlowLiteC
The actual error for me is:
building for iOS Simulator, but linking in object file built for iOS, file '/Users/kevinw/Development/flutter/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-0.9.0/ios/TensorFlowLiteC.framework/TensorFlowLiteC' for architecture arm64
This compiles and run fine when built on an iPhone 12 device, but I need to use the simulator for testing the app.
I think maybe a solution is to compile TensorFlowLiteC on the M1 with macOS arch enabled, but bazel has some very strange configurations for building it and I haven't been able to figure that out. I am running on an M1 with Monterey v 12.0.1, and Xcode 13.1 and Flutter 2.5.3.
I could update flutter to latest, but I suspect that will lead to more issues. Were you able to get yours compiling with similar setup? Thanks again!
I got it working with a custom build, though I'm not happy about having to manually linking in diff library just to run on simulator. Here's the build I used which works on the sim:
https://github.com/revolut-mobile/TensorFlowLiteC-binary/releases/tag/2.5.0
It's too bad they didn't combine the two architectures into one that works for both. Also, this is untested on android as of yet, so I'm sure that architecture needs to be added as well...the one that ships with this package works for both android and iOS devices (just not sim).
I got it working with a custom build, though I'm not happy about having to manually linking in diff library just to run on simulator. Here's the build I used which works on the sim:
https://github.com/revolut-mobile/TensorFlowLiteC-binary/releases/tag/2.5.0
It's too bad they didn't combine the two architectures into one that works for both. Also, this is untested on android as of yet, so I'm sure that architecture needs to be added as well...the one that ships with this package works for both android and iOS devices (just not sim).
When i use this file, I am able to compile the application. But when I try to use any function of this package it fails with an error message saying that it failed to lookup that function.
For example when I want to create a classifier instance with NLClassifier.createFromAsset('assets/$_modelFile')
from the tflite_flutter_helper
package I get:
Failed to lookup symbol 'NLClassifierFromFileAndOptions': dlsym(RTLD_DEFAULT, NLClassifierFromFileAndOptions): symbol not found
How can I fix this?
I have the same problem and I've resolved using these instructions. The problem is because with the release of Xcode 12, $ARCHS_STANDARD includes arm64 for simulator builds, so you should add
arm64
inEXCLUDED_ARCHS
setting, maintaining original settingi386
. Unfortunately, this doesn't work inDebug.xcconfig
: you should set it instead in yourPodfile
adding this build configuration setting:post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386 arm64' end end end
you save my life.
0. @ricibald ricibald Podfile
setting
-
/YourProject/ios/TensorFlowLiteC.framework
copy into/YourProject/ios/.symlinks/plugins/tflite_flutter/ios/
-
flutter clean && flutter pub get
-
arch -x86_64 pod install
- solved
https://github.com/am15h/tflite_flutter_plugin/issues/153#issuecomment-1126694294
This worked for me, thank you!