build(nc-native-android): clean build script

This commit is contained in:
pierre
2023-05-31 17:31:24 +02:00
parent 8432c30f6c
commit 365e0134b4
5 changed files with 39 additions and 29 deletions
+4 -14
View File
@@ -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 }}
+5 -4
View File
@@ -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
+30 -11
View File
@@ -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