浏览代码

Build APKs on releasing a new version (#209)

Fangjun Kuang 2 年之前
父节点
当前提交
95fe746925
共有 4 个文件被更改,包括 133 次插入2 次删除
  1. 54 0
      .github/workflows/apk.yaml
  2. 1 1
      CMakeLists.txt
  3. 1 1
      android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn/MainActivity.kt
  4. 77 0
      build-apk.sh

+ 54 - 0
.github/workflows/apk.yaml

@@ -0,0 +1,54 @@
+name: apk
+
+on:
+  push:
+    branches:
+      - apk
+    tags:
+      - '*'
+
+concurrency:
+  group: apk-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: write
+
+jobs:
+  apk:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest]
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - name: Display NDK HOME
+        shell: bash
+        run: |
+          echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}"
+          ls -lh ${ANDROID_NDK_LATEST_HOME}
+
+      - name: build APK
+        shell: bash
+        run: |
+          export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME
+          ./build-apk.sh
+
+      - name: Display APK
+        shell: bash
+        run: |
+          ls -lh ./apks/
+
+      - uses: actions/upload-artifact@v2
+        with:
+          path: ./apks/*.apk
+
+      - name: Release APK
+        uses: svenstaro/upload-release-action@v2
+        with:
+          file_glob: true
+          file: apks/*.apk

+ 1 - 1
CMakeLists.txt

@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
 project(sherpa-ncnn)
 
-set(SHERPA_NCNN_VERSION "2.0")
+set(SHERPA_NCNN_VERSION "2.0.1")
 
 # Disable warning about
 #

+ 1 - 1
android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn/MainActivity.kt

@@ -182,7 +182,7 @@ class MainActivity : AppCompatActivity() {
             featureDim = 80
         )
         //Please change the argument "type" if you use a different model
-        val modelConfig = getModelConfig(type = 2, useGPU = true)!!
+        val modelConfig = getModelConfig(type = 2, useGPU = useGPU)!!
         val decoderConfig = getDecoderConfig(method = "greedy_search", numActivePaths = 4)
 
         val config = RecognizerConfig(

+ 77 - 0
build-apk.sh

@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+
+# Please set the environment variable ANDROID_NDK
+# before running this script
+
+# Inside the $ANDROID_NDK directory, you can find a binary ndk-build
+# and some other files like the file "build/cmake/android.toolchain.cmake"
+
+set -e
+
+log() {
+  # This function is from espnet
+  local fname=${BASH_SOURCE[1]##*/}
+  echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
+}
+
+SHERPA_NCNN_VERSION=$(grep "SHERPA_NCNN_VERSION" ./CMakeLists.txt  | cut -d " " -f 2  | cut -d '"' -f 2)
+
+log "Building APK for sherpa-ncnn v${SHERPA_NCNN_VERSION}"
+
+log "====================arm64-v8a================="
+./build-android-arm64-v8a.sh
+log "====================x86-64===================="
+./build-android-armv7-eabi.sh
+log "====================armv7-eabi================"
+./build-android-x86-64.sh
+log "----------------------------------------------"
+
+
+# Download the model
+# see https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/zipformer-transucer-models.html#csukuangfj-sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13-bilingual-chinese-english
+repo_url=https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13
+log "Start testing ${repo_url}"
+repo=$(basename $repo_url)
+log "Download pretrained model and test-data from $repo_url"
+GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
+pushd $repo
+git lfs pull --include "*.bin"
+
+# remove .git to save spaces
+rm -rf .git
+rm -rfv test_wavs
+rm -v export-for-ncnn-bilingual.sh
+rm README.md
+ls -lh
+popd
+
+mv -v $repo ./android/SherpaNcnn/app/src/main/assets/
+tree ./android/SherpaNcnn/app/src/main/assets/
+
+mkdir -p apks
+
+for arch in arm64-v8a armeabi-v7a x86_64; do
+  log "------------------------------------------------------------"
+  log "build apk for $arch"
+  log "------------------------------------------------------------"
+  src_arch=$arch
+  if [ $arch == "armeabi-v7a" ]; then
+    src_arch=armv7-eabi
+  elif [ $arch == "x86_64" ]; then
+    src_arch=x86-64
+  fi
+
+  ls -lh ./build-android-$src_arch/install/lib/*.so
+
+  cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaNcnn/app/src/main/jniLibs/$arch/
+
+  pushd ./android/SherpaNcnn
+  ./gradlew build
+  popd
+
+  mv android/SherpaNcnn/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-ncnn-${SHERPA_NCNN_VERSION}-cpu-$arch-bilingual-en-zh.apk
+  ls -lh apks
+  rm -v ./android/SherpaNcnn/app/src/main/jniLibs/$arch/*.so
+done
+
+ls -lh apks/