tflite_flutter_plugin icon indicating copy to clipboard operation
tflite_flutter_plugin copied to clipboard

iOS simulator cannot be used

Open hapasa opened this issue 3 years ago • 15 comments

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.

hapasa avatar Sep 13 '21 19:09 hapasa

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.

purplenoodlesoop avatar Sep 15 '21 00:09 purplenoodlesoop

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

ricibald avatar Sep 24 '21 09:09 ricibald

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.

physxP avatar Oct 12 '21 14:10 physxP

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.

lusattdev avatar Oct 24 '21 10:10 lusattdev

@mantaBracket I figured out the problem. When you build on Xcode error is shown while linking TensorflowLiteC.framework: image 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.

physxP avatar Oct 24 '21 10:10 physxP

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.

lusattdev avatar Oct 24 '21 12:10 lusattdev

Thanks a lot @physxP it work!

YFrendo avatar Dec 06 '21 15:12 YFrendo

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 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

guccisekspir avatar Dec 12 '21 10:12 guccisekspir

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 avatar Jan 05 '22 19:01 klivin

@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 avatar Jan 05 '22 21:01 physxP

@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!

klivin avatar Jan 05 '22 22:01 klivin

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).

klivin avatar Jan 06 '22 00:01 klivin

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?

yordikurk avatar Apr 19 '22 14:04 yordikurk

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

you save my life. 0. @ricibald ricibald Podfile setting

  1. /YourProject/ios/TensorFlowLiteC.framework copy into /YourProject/ios/.symlinks/plugins/tflite_flutter/ios/
  2. flutter clean && flutter pub get
  3. arch -x86_64 pod install
  4. solved

yogithesymbian avatar May 14 '22 11:05 yogithesymbian

https://github.com/am15h/tflite_flutter_plugin/issues/153#issuecomment-1126694294

This worked for me, thank you!

saifb avatar May 16 '22 20:05 saifb