-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide sherpa-onnx.aar for Android (#1615)
- Loading branch information
1 parent
9d4659f
commit 4dc4f1a
Showing
44 changed files
with
881 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ concurrency: | |
|
||
jobs: | ||
build-android-libs: | ||
name: Android for ${{ matrix.os }} | ||
name: Android libs | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
|
@@ -44,6 +44,11 @@ jobs: | |
with: | ||
fetch-depth: 0 | ||
|
||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ${{ matrix.os }}-android-jni | ||
|
||
- name: Display NDK HOME | ||
shell: bash | ||
run: | | ||
|
@@ -53,6 +58,9 @@ jobs: | |
- name: build android arm64-v8a | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | ||
./build-android-arm64-v8a.sh | ||
mkdir -p jniLibs/arm64-v8a/ | ||
|
@@ -62,6 +70,9 @@ jobs: | |
- name: build android armv7-eabi | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | ||
./build-android-armv7-eabi.sh | ||
mkdir -p ./jniLibs/armeabi-v7a/ | ||
|
@@ -71,6 +82,9 @@ jobs: | |
- name: build android x86_64 | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | ||
./build-android-x86-64.sh | ||
mkdir -p ./jniLibs/x86_64 | ||
|
@@ -80,6 +94,9 @@ jobs: | |
- name: build android x86 | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | ||
./build-android-x86.sh | ||
mkdir -p ./jniLibs/x86 | ||
|
@@ -143,3 +160,129 @@ jobs: | |
file_glob: true | ||
overwrite: true | ||
file: sherpa-onnx-*-android.tar.bz2 | ||
|
||
build-android-aar: | ||
needs: [build-android-libs] | ||
name: Android AAR | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# https://github.com/actions/setup-java | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' # See 'Supported distributions' for available options | ||
java-version: '21' | ||
|
||
- name: Display NDK HOME | ||
shell: bash | ||
run: | | ||
echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" | ||
ls -lh ${ANDROID_NDK_LATEST_HOME} | ||
- name: Retrieve artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: sherpa-onnx-android-libs | ||
path: /tmp/jniLibs | ||
|
||
- name: Show jni libs | ||
shell: bash | ||
run: | | ||
ls -lh /tmp/jniLibs | ||
# drwxr-xr-x 2 runner docker 4.0K Dec 12 06:56 arm64-v8a | ||
# drwxr-xr-x 2 runner docker 4.0K Dec 12 06:56 armeabi-v7a | ||
# drwxr-xr-x 2 runner docker 4.0K Dec 12 06:56 x86 | ||
# drwxr-xr-x 2 runner docker 4.0K Dec 12 06:56 x86_64 | ||
# | ||
- name: Copy libs | ||
shell: bash | ||
run: | | ||
for arch in arm64-v8a armeabi-v7a x86 x86_64; do | ||
cp -v /tmp/jniLibs/$arch/* android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/$arch/ | ||
done | ||
- name: Check libs | ||
shell: bash | ||
run: | | ||
ls -lh android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/* | ||
- name: Build aar | ||
shell: bash | ||
run: | | ||
cd android/SherpaOnnxAar | ||
./gradlew :sherpa_onnx:assembleRelease | ||
- name: Display aar | ||
shell: bash | ||
run: | | ||
cd android/SherpaOnnxAar | ||
ls -lh ./sherpa_onnx/build/outputs/aar/sherpa_onnx-release.aar | ||
cp ./sherpa_onnx/build/outputs/aar/sherpa_onnx-release.aar ../../ | ||
- name: Rename aar | ||
shell: bash | ||
run: | | ||
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
echo "SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION" >> "$GITHUB_ENV" | ||
mv sherpa_onnx-release.aar sherpa-onnx-${SHERPA_ONNX_VERSION}.aar | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: sherpa-onnx-android-aar | ||
path: ./*.aar | ||
|
||
# https://huggingface.co/docs/hub/spaces-github-actions | ||
- name: Publish to huggingface | ||
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
uses: nick-fields/retry@v3 | ||
with: | ||
max_attempts: 20 | ||
timeout_seconds: 200 | ||
shell: bash | ||
command: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
du -h -d1 . | ||
ls -lh | ||
rm -rf huggingface | ||
export GIT_CLONE_PROTECTION_ACTIVE=false | ||
GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:[email protected]/csukuangfj/sherpa-onnx-libs huggingface | ||
cd huggingface | ||
dst=android/aar | ||
mkdir -p $dst | ||
cp -v ../*.aar $dst | ||
git status | ||
git lfs track "*.aar" | ||
git add . | ||
git commit -m "upload sherpa-onnx-${SHERPA_ONNX_VERSION}.aar" | ||
git push https://csukuangfj:[email protected]/csukuangfj/sherpa-onnx-libs main | ||
- name: Release android aar | ||
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/') | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
file_glob: true | ||
overwrite: true | ||
file: ./*.aar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Usage of this project | ||
|
||
``` | ||
git clone https://github.com/k2-fsa/sherpa-onnx | ||
cd sherpa-onnx | ||
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.34/sherpa-onnx-v1.10.34-android.tar.bz2 | ||
tar xvf sherpa-onnx-v1.10.34-android.tar.bz2 | ||
cp -v jniLibs/arm64-v8a/* android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/arm64-v8a/ | ||
cp -v jniLibs/armeabi-v7a/* android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/armeabi-v7a/ | ||
cp -v jniLibs/x86/* android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/x86/ | ||
cp -v jniLibs/x86_64/* android/SherpaOnnxAar/sherpa_onnx/src/main/jniLibs/x86_64/ | ||
cd android/SherpaOnnxAar | ||
./gradlew :sherpa_onnx:assembleRelease | ||
ls -lh ./sherpa_onnx/build/outputs/aar/sherpa_onnx-release.aar | ||
cp ./sherpa_onnx/build/outputs/aar/sherpa_onnx-release.aar ../../sherpa-onnx-1.10.34.aar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
alias(libs.plugins.android.application) apply false | ||
alias(libs.plugins.jetbrains.kotlin.android) apply false | ||
alias(libs.plugins.android.library) apply false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. For more details, visit | ||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects | ||
# org.gradle.parallel=true | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Kotlin code style for this project: "official" or "obsolete": | ||
kotlin.code.style=official | ||
# Enables namespacing of each library's R class so that its R class includes only the | ||
# resources declared in the library itself and none from the library's dependencies, | ||
# thereby reducing the size of the R class for that library | ||
android.nonTransitiveRClass=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[versions] | ||
agp = "8.4.0" | ||
kotlin = "1.7.20" | ||
coreKtx = "1.15.0" | ||
junit = "4.13.2" | ||
junitVersion = "1.2.1" | ||
espressoCore = "3.6.1" | ||
appcompat = "1.7.0" | ||
material = "1.12.0" | ||
|
||
[libraries] | ||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } | ||
junit = { group = "junit", name = "junit", version.ref = "junit" } | ||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } | ||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } | ||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } | ||
material = { group = "com.google.android.material", name = "material", version.ref = "material" } | ||
|
||
[plugins] | ||
android-application = { id = "com.android.application", version.ref = "agp" } | ||
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } | ||
android-library = { id = "com.android.library", version.ref = "agp" } | ||
|
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
android/SherpaOnnxAar/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Thu Dec 12 14:02:30 CST 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.