From 62ccb6b4cdfe1ab3039e95193eace28866e3f732 Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 1 Jun 2023 19:20:32 +0200 Subject: [PATCH] build(ns5-android): add product flavors config --- .github/workflows/nyms5-android-build.yml | 15 +++--- nym-connect/native/android/README.md | 46 +++++++++++++++--- nym-connect/native/android/app/build.gradle | 54 ++++++++++++++++++--- 3 files changed, 93 insertions(+), 22 deletions(-) diff --git a/.github/workflows/nyms5-android-build.yml b/.github/workflows/nyms5-android-build.yml index 231ead1d6e..82fcfbc2cb 100644 --- a/.github/workflows/nyms5-android-build.yml +++ b/.github/workflows/nyms5-android-build.yml @@ -60,29 +60,28 @@ jobs: working-directory: sdk/lib/socks5-listener/ env: RELEASE: true + # build for arm64 and x86_64 run: ./build-android.sh aarch64 x86_64 - name: Build APKs (unsigned debug) working-directory: nym-connect/native/android env: ANDROID_SDK_ROOT: ${{ env.ANDROID_HOME }} - run: ./gradlew :app:assembleDebug + # build for arm64 and x86_64 + run: ./gradlew :app:assembleArch64Debug - name: Prepare APKs run: | - mkdir apk/ - mv nym-connect/native/android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk \ - apk/nyms5-arm64-debug.apk - mv nym-connect/native/android/app/build/outputs/apk/debug/app-x86_64-debug.apk \ - apk/nyms5-x86_64-debug.apk + mkdir apk + mv nym-connect/native/android/app/build/outputs/apk/arch64/debug/app-arch64-debug.apk \ + apk/nyms5-arch64-debug.apk - name: Upload APKs uses: actions/upload-artifact@v3 with: name: nyms5-apk-debug path: | - apk/nyms5-arm64-debug.apk - apk/nyms5-x86_64-debug.apk + apk/nyms5-arch64-debug.apk # publish: # name: Publish APK diff --git a/nym-connect/native/android/README.md b/nym-connect/native/android/README.md index 4c48e68110..b2a92f2454 100644 --- a/nym-connect/native/android/README.md +++ b/nym-connect/native/android/README.md @@ -6,15 +6,22 @@ _TODO_ ### Getting started -Install Android Studio and open the project. +[Install](https://developer.android.com/studio/install) Android Studio and open +the project.\ +Setup an android emulator using AVD.\ +[Run](https://developer.android.com/studio/run/emulator) the project. + +**⚠ NOTE**: be sure +to [set](https://developer.android.com/studio/run#changing-variant) +the build variant to `x86_64Debug` when running on emulator ### Lib Nym socks5 -This Application needs the native [nym-socks5-listener](https://github.com/nymtech/nym/blob/develop/sdk/lib/socks5-listener/Cargo.toml) +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 for arch x64 and arm (x64 is mainly for android emulator, arm -for APK distribution), from the root of the repo run +To build it for x86_64 and arm64 arch, from the root of the repo run ```shell cd sdk/lib/socks5-listener/ @@ -24,10 +31,35 @@ cd sdk/lib/socks5-listener/ To build in release mode run ```shell -RELEASE=true ./build-android.sh aarch64 +RELEASE=true ./build-android.sh aarch64 x86_64 ``` -The shared library for each ABIs will be automatically moved into +The shared library for each ABIs will be automatically moved into `app/src/main/jniLibs/*` directories. -### Run _TODO_ \ No newline at end of file +### APK build (from terminal) + +This project is setup with multiple [product flavors](app/build.gradle) to +build for specific architectures.\ +Supported archs: + +- arm64 +- arm (old arm) +- x86_64 +- x86 + +For example to build for _arm64_ in _release_ mode use + +```shell +./gradlew :app:assembleArm64Release +``` + +**NOTE**: you likely want _arch64_ (`arm64` & `x86_64`) for APK distribution + +To build a _universal_ APK which includes all ABI use + +```shell +./gradlew :app:assembleUniversalRelease +``` + +**⚠ WARNING**: APK size will be multiplied diff --git a/nym-connect/native/android/app/build.gradle b/nym-connect/native/android/app/build.gradle index f8612e727b..63e9a51fe1 100644 --- a/nym-connect/native/android/app/build.gradle +++ b/nym-connect/native/android/app/build.gradle @@ -23,20 +23,60 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - splits { - abi { - enable true - reset() - include "x86_64", "arm64-v8a" - universalApk true + flavorDimensions "abi" + productFlavors { + universal { + dimension "abi" + ndk { + abiFilters "arm64-v8a", "armeabi-v7a", "x86_64", "x86" + } + } + arch64 { + dimension "abi" + ndk { + abiFilters "arm64-v8a", "x86_64" + } + } + arm64 { + dimension "abi" + ndk { + abiFilters "arm64-v8a" + } + } + arm { + dimension "abi" + ndk { + abiFilters "armeabi-v7a" + } + } + x86_64 { + dimension "abi" + ndk { + abiFilters "x86_64" + } + } + x86 { + dimension "abi" + ndk { + abiFilters "x86" + } } } +// splits { +// abi { +// enable true +// reset() +// include "x86_64", "arm64-v8a" +// universalApk true +// } +// } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8