Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flutter] Can not work on iOS Simulator #1283

Closed
hantrungkien opened this issue Aug 24, 2024 · 19 comments
Closed

[Flutter] Can not work on iOS Simulator #1283

hantrungkien opened this issue Aug 24, 2024 · 19 comments

Comments

@hantrungkien
Copy link
Contributor

hantrungkien commented Aug 24, 2024

I got a error when tap on the Generate button from the example:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libsherpa-onnx-c-api.dylib': dlopen(libsherpa-onnx-c-api.dylib, 0x0001): tried: '/Library/Developer/CoreSimulator/Volumes/iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRootlibsherpa-onnx-c-api.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libsherpa-onnx-c-api.dylib' (no such file), '/usr/lib/swift/libsherpa-onnx-c-api.dylib' (no such file, not in dyld cache), '/Users/kienht/Library/Developer/CoreSimulator/Devices/5E910182-EC7E-48A6-99AC-E2FA3CBDF9D4/data/Containers/Bundle/Application/91543D27-FF1F-4554-B087-036C4127DDB2/Runner.app/Frameworks/libsherpa-onnx-c-api.dylib' (mach-o file (/Users/kienht/Library/Developer/CoreSimulator/Devices/5E910182-EC7E-48A6-99AC-E2FA3CBDF9D4/data/<…>

@csukuangfj
Copy link
Collaborator

The fix is:

Step 1. Run
https://github.com/k2-fsa/sherpa-onnx/blob/master/build-ios-shared.sh

You have to build the lib for simulator by yourself. The lib in the package published to pub.dev is for iOS Phone only.

The following is a screenshot after running the above script

48d5179b1d8d3dddb613f581c91027d5

Note that there are libs for simulator arm64 and for simulator x86_64. You need to select the correct one by yourself.

Step 2. Use the generated lib for simulator from step 1 to replace the one you downloaded from pub.dev

For instance, find the .dart_tool directory in your project,
image

Open package_config.json from .dart_tool:
image

Locate where sherpa-onnx-ios is saved from package_config.json:

image

In the above screenshot, you can find the directory for the package sherpa_onnx_ios

06849c41b22423bae2a3275ead5bd72f

image

Now copy the libonnxruntime.a and libsherpa-onnx-c-api.dylib from step1 to the above directory
and everything should work as expected.

@csukuangfj
Copy link
Collaborator

@hantrungkien Does it work now?

@hantrungkien
Copy link
Contributor Author

@csukuangfj Many thanks. I'm doing on other higher priority tasks for our release day. I will back to it on tonight or tomorrow and give you a feedback. Thanks again 🙏

@hantrungkien
Copy link
Contributor Author

@csukuangfj Sorry for late. I want to report about your way, it works. Many many thanks 🙏

@csukuangfj
Copy link
Collaborator

Great to hear it fixes your issue!

@keyur2maru
Copy link

keyur2maru commented Sep 25, 2024

@csukuangfj Thanks for the solution, fixed the same issue for me as well. But I wonder if combining IOS and IOS-simulator into a single binary would be possible? Or is there another way to easily run on a simulator as well as a real device without having to change these libs every time one switches between IOS and simulator?

@csukuangfj
Copy link
Collaborator

yes, it is possible.

The problem is that pub.dev forbids uploading packages more than 100MB

If they were combined, it would be larger than 100MB. The main contribution to the file.size comes from onnxruntime

@keyur2maru
Copy link

keyur2maru commented Sep 25, 2024

yes, it is possible.

The problem is that pub.dev forbids uploading packages more than 100MB

If they were combined, it would be larger than 100MB. The main contribution to the file.size comes from onnxruntime

Can you please share the method to combine them?
If you can do so, I would create a fork and point my application's pubspec.yaml to this new fork allowing for easier testing between real and simulated device.

@csukuangfj
Copy link
Collaborator

One of the methods is to create a framework or a xcframework.

We currently don't have code for that, but it is feasible. You need to figure out how to do that by yourself.

@keyur2maru
Copy link

@csukuangfj Thanks for your suggestion, creating xcframework did the trick!

mkdir ios-simulator
lipo -create \                                     
    ios-arm64-simulator/libsherpa-onnx-c-api.dylib \
    ios-x86_64-simulator/libsherpa-onnx-c-api.dylib \
    -output ios-simulator/libsherpa-onnx-c-api.dylib

xcodebuild -create-xcframework \
    -library ios-arm64/libsherpa-onnx-c-api.dylib \
    -headers build/os64/install/include/ \
    -library ios-simulator/libsherpa-onnx-c-api.dylib \
    -headers build/simulator_arm64/install/include/ \
    -output SherpaOnnx.xcframework

I copied SherpaOnnx.xcframework and sherpa-onnx/build-ios-shared/ios-onnxruntime/1.17.1/onnxruntime.xcframework to .pub-cache/hosted/pub.dev/sherpa_onnx_ios-1.10.27/ios

Also replaced the following line @ .pub-cache/hosted/pub.dev/sherpa_onnx_ios-1.10.27/ios/sherpa_onnx_ios.podspec
FROM
s.ios.vendored_libraries = '*.dylib', '*.a'
TO
s.vendored_frameworks = 'SherpaOnnx.xcframework', 'onnxruntime.xcframework'

Finally, added both frameworks to my application Runner
image

@hantrungkien
Copy link
Contributor Author

@keyur2maru Thanks for your way but I got a error when building

Error (Xcode): 21 duplicate symbols

Could you please help me?

@csukuangfj
Copy link
Collaborator

csukuangfj commented Oct 25, 2024

@keyur2maru Thanks for your way but I got a error when building

Error (Xcode): 21 duplicate symbols

Could you please help me?

Would you mind posting complete logs?

@hantrungkien
Copy link
Contributor Author

@csukuangfj sorry, let's ignore the above error for now. I'm having trouble distributing the app via Testflight. I don't know if it's really necessary to add them to pubspec.yaml?

vits-piper-en_US.py
vits-piper-en_US.sh

 Error uploading ipa file: 
 [Application Loader Error Output]: [ContentDelivery.Uploader.600003BA41C0] Asset validation failed (90035) Invalid Signature. Code object is not signed at all. The file at path “Runner.app/Frameworks/App.framework/flutter_assets/assets/vits-piper-en_US-libritts_r-medium/vits-piper-en_US.py” is not properly signed. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose “Clean All” in Xcode, delete the “build” directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/support/code-signing. (ID: 86b90e2e-370a-4c09-b95a-8d7c7b19d27d)
[Application Loader Error Output]: [ContentDelivery.Uploader.600003BA41C0] Asset validation failed (90035) Invalid Signature. Code object is not signed at all. The file at path “Runner.app/Frameworks/App.framework/flutter_assets/assets/vits-piper-en_US-libritts_r-medium/vits-piper-en_US.sh” is not properly signed. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose “Clean All” in Xcode, delete the “build” directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/support/code-signing. (ID: bf49fe73-f655-44ac-aa56-9d41e884c5cc)
Screenshot 2024-10-25 at 15 14 43

@csukuangfj
Copy link
Collaborator

please just delete them. You don't need them.

@hantrungkien
Copy link
Contributor Author

@csukuangfj I was able to upload to testflight but it was rejected. Please help me

Screenshot 2024-10-25 at 15 53 43

@hantrungkien
Copy link
Contributor Author

@csukuangfj I tried like #1172 (comment) but still can not distribute via testflight. Please help me!

@csukuangfj
Copy link
Collaborator

sorry, the logs are not informative

@hantrungkien
Copy link
Contributor Author

@csukuangfj After 1 day research, I found a reason is:

Dynamic libraries outside of a framework bundle, which typically have the file extension .dylib, are not supported on iOS.

But I still don't found a solution...

@csukuangfj
Copy link
Collaborator

Please use the latest release v1.10.31

You don't need to change any code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants