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

Support linking onnxruntime statically for Android #1619

Merged

Conversation

csukuangfj
Copy link
Collaborator

@csukuangfj csukuangfj commented Dec 14, 2024

This PR supports linking onnxruntime statically for Android (arm64-v8a, x86_64, and armeabi-v7a).

You need to run

export BUILD_SHARED_LIBS=OFF

./build-android-arm64-v8a.sh
./build-android-armv7-eabi.sh
./build-android-x86-64.sh

In the end, you only get one lib libsherpa-onnx-jni.so and you don't need to copy libonnxruntime.a to your project.

Note that if you download and unzip the onnxruntime static lib and you will find its size is about 1GB.

fangjuns-MacBook-Pro:build-android-x86-64-static fangjun$ ls -lh 1.17.1-static/lib/
total 1992056
-rw-r--r--  1 fangjun  staff   973M Dec 13 15:48 libonnxruntime.a

fangjuns-MacBook-Pro:build-android-x86-64-static fangjun$ ls -lh install/lib/libsherpa-onnx-jni.so
-rwxr-xr-x  1 fangjun  staff    23M Dec 13 17:05 install/lib/libsherpa-onnx-jni.so

Comparison of using static and dynamic link of onnxruntime in the final APK

Link onnxruntime statically Link onnxruntime dynamically
You only need libsherpa-onnx-jni.so You need libsherpa-onnx-jni.so and libonnxruntime.so
Screenshot 2024-12-13 at 17 20 50 Screenshot 2024-12-13 at 16 55 30

You can find pre-built aar files in the release page, e.g.,
https://github.com/k2-fsa/sherpa-onnx/releases/tag/v1.10.35

Screenshot 2024-12-14 at 09 46 55

@csukuangfj csukuangfj merged commit e639c70 into k2-fsa:master Dec 14, 2024
179 of 206 checks passed
@csukuangfj csukuangfj deleted the android-link-onnxruntime-statically branch December 14, 2024 01:53
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

Successfully merging this pull request may close these issues.

1 participant