diff --git a/.github/workflows/nyms5-android-build.yml b/.github/workflows/nyms5-android-build.yml index f4044ea8dc..231ead1d6e 100644 --- a/.github/workflows/nyms5-android-build.yml +++ b/.github/workflows/nyms5-android-build.yml @@ -1,7 +1,7 @@ -name: Nyms5 APK build +name: Nyms5 Android # unsigned debug APKs only, supported archs: -# - x86_64 # - arm64-v8a +# - x86_64 on: workflow_dispatch: @@ -55,24 +55,14 @@ jobs: run: | rustup target add aarch64-linux-android \ x86_64-linux-android - # armv7-linux-androideabi \ - # i686-linux-android \ - - - name: Clean android project - working-directory: nym-connect/native/android - env: - RELEASE: true - run: | - rm nym-connect/native/android/app/src/main/jniLibs/arm64-v8a/libnym_socks5_listener.so || true - rm nym-connect/native/android/app/src/main/jniLibs/x86_64/libnym_socks5_listener.so || true - name: Build lib nym-socks5-listener working-directory: sdk/lib/socks5-listener/ env: RELEASE: true - run: ./build-android.sh + run: ./build-android.sh aarch64 x86_64 - - name: Build APK (debug) + - name: Build APKs (unsigned debug) working-directory: nym-connect/native/android env: ANDROID_SDK_ROOT: ${{ env.ANDROID_HOME }} diff --git a/nym-connect/native/android/README.md b/nym-connect/native/android/README.md index a192ed73b4..4c48e68110 100644 --- a/nym-connect/native/android/README.md +++ b/nym-connect/native/android/README.md @@ -13,17 +13,18 @@ Install Android Studio and open the project. This Application needs the native [nym-socks5-listener](https://github.com/nymtech/nym/blob/develop/sdk/lib/socks5-listener/Cargo.toml) library in order to work. -To build it, from the root of the repo run +To build it for arch x64 and arm (x64 is mainly for android emulator, arm +for APK distribution), from the root of the repo run ```shell cd sdk/lib/socks5-listener/ -./build-android.sh +./build-android.sh aarch64 x86_64 ``` -To build in release mode +To build in release mode run ```shell -RELEASE=true ./build-android.sh +RELEASE=true ./build-android.sh aarch64 ``` The shared library for each ABIs will be automatically moved into diff --git a/nym-connect/native/android/app/src/main/jniLibs/armeabi-v7a/.gitkeep b/nym-connect/native/android/app/src/main/jniLibs/armeabi-v7a/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nym-connect/native/android/app/src/main/jniLibs/i686/.gitkeep b/nym-connect/native/android/app/src/main/jniLibs/i686/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/lib/socks5-listener/build-android.sh b/sdk/lib/socks5-listener/build-android.sh index 92e03c6bc8..8f199d347a 100755 --- a/sdk/lib/socks5-listener/build-android.sh +++ b/sdk/lib/socks5-listener/build-android.sh @@ -1,11 +1,17 @@ #!/bin/bash - +# +# Usage +# +# build-android.sh [ARCH ...] +# # This script builds the lib for android and moves the shared # objects (*.so) into the right app's directories # -# currently it builds for: +# ARCH: # - aarch64 (arm 64) -# - x86_64 (classic PC 64) +# - x86_64 (classic PC 64) +# - i686 (x86) +# - armv7 # # ⚠ to build for release set the env var `RELEASE=true` @@ -36,24 +42,37 @@ export TARGET_RANLIB="$TOOLCHAIN/bin/llvm-ranlib" export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$TOOLCHAIN/bin/x86_64-linux-android$API-clang" export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$TOOLCHAIN/bin/aarch64-linux-android$API-clang" +# arch mapping between Rust targets (keys) and Android ABIs (values) +# https://developer.android.com/ndk/guides/abis.html +declare -A arch_map=([x86_64]="x86_64" [aarch64]="arm64-v8a" [armv7]="armeabi-v7a" [i686]="x86") + output_dir=../../../target jni_dir=../../../nym-connect/native/android/app/src/main/jniLibs +lib=libnym_socks5_listener.so build () { + abi="${arch_map[$1]}" echo -e " $B_YLW⚡$RS building for arch $BLD$1$RS" export TARGET_CC="$TOOLCHAIN/bin/$1-linux-android$API-clang" + if [ -a "$jni_dir/$abi/$lib" ]; then + # remove any previously built library + rm "$jni_dir/$abi/$lib" + fi if [ "$RELEASE" = true ]; then cargo build --lib --target "$1-linux-android" --release - mv "$output_dir/$1-linux-android/release/libnym_socks5_listener.so" "$jni_dir/$2/" + mv "$output_dir/$1-linux-android/release/$lib" "$jni_dir/$abi/" else cargo build --lib --target "$1-linux-android" - mv "$output_dir/$1-linux-android/debug/libnym_socks5_listener.so" "$jni_dir/$2/" + mv "$output_dir/$1-linux-android/debug/$lib" "$jni_dir/$abi/" fi - echo -e " $B_GRN✓$RS lib successfully builded for $BLD$1$RS, moved under app's dir$BLD jniLibs/$2/$RS" + echo -e " $B_GRN✓$RS lib built successfully for $BLD$1$RS, moved under app's dir$BLD jniLibs/$abi/$RS" } -# build for x86_64 -build x86_64 x86_64 - -# build for aarch64 -build aarch64 arm64-v8a +for arch in "$@"; do + if [ "${arch_map[$arch]}" ]; then + build "$arch" + else + echo -e " $B_RED✗$RS unknown arch $BLD$arch$RS" + exit 1 + fi +done