Building

The APK, from the native build of each ABI given (one APK holds them all; Android installs the device's):

scripts/android-apk.sh ~/android-build arm64-v8a x86_64
adb install -r ~/android-build/stage/gradle/outputs/apk/debug/ScarletNX-debug.apk

They need the NDK (ANDROID_NDK_ROOT, else the newest under $ANDROID_HOME/ndk), the SDK (ANDROID_HOME), Gradle 9 (GRADLE, default gradle) and a JDK 17 or newer (JAVA_HOME). Extra CMake arguments go after --. ANDROID_API (default 21) is the oldest Android the script builds for, the app's minSdk. android-apk.sh installs each build into <out>/stage (the libraries, SDL's Java classes and the icon), which dist/android/build.gradle packs with the two activities; Gradle's own output goes there too. The CI does the same on every push (.github/workflows/build.yml): an APK per ABI, and one holding both.

Signing

Android installs an APK over the app it has only when the same key signed both. One key signs every APK of the repository's own builds, so each installs over the one before: the CI takes it from the ANDROID_KEYSTORE secret (a keystore in base64), its password, the keystore's and the key's, from ANDROID_KEYSTORE_PASSWORD, and checks the APK's certificate against the ANDROID_CERT_SHA256 variable. A fork's pull request has no secrets: its APKs carry the runner's own debug key, which its log says, and install only after the app is uninstalled. A local build takes the keystore from SNX_ANDROID_KEYSTORE and its password from SNX_ANDROID_KEYSTORE_PASSWORD (the key is scarletnx, or SNX_ANDROID_KEY_ALIAS); without them this machine's own debug key signs. The key is made once:

keytool -genkeypair -keystore scarletnx.keystore -alias scarletnx -keyalg RSA -keysize 4096 -validity 36500 \
    -dname "CN=ScarletNX"
keytool -exportcert -keystore scarletnx.keystore -alias scarletnx | sha256sum   # ANDROID_CERT_SHA256

An app installed from an APK another key signed has to be uninstalled once; what it keeps in ScarletNX/ on the shared storage stays.

The Android emulator runs it on an x86_64 image; -gpu swiftshader_indirect gives it SwiftShader's Vulkan 1.3. Its ARM translation runs the arm64 build too (an APK with arm64 alone, or an arm64 program from adb shell), slowly.

Tests

The app's unit tests (dist/android/src/test) run on the computer, from the stage android-apk.sh made: the app's classes build against SDL's Java there.

gradle -p dist/android testDebugUnitTest -Pscarletnx.stage=$HOME/android-build/stage

JUnit alone checks what needs nothing of Android: the setting a maker's phone gets, that each method the native code calls by name is in the app and that each native method is in the native code. Robolectric runs the rest on Android's own classes: the data folder's provider, what the menu hands the Files app and the share sheet, a game's arguments, what a PLAY hands the menu, the shortcuts and the recompile's notification. Its first run fetches those classes for the app's targetSdk from Maven Central (about 210 MB, into ~/.m2). The CI runs the tests at the end of its Android job: one that fails fails the job, with the APKs already uploaded.


Made from docs/hosts/android-app.md at 69237645142c. GPL-3.0-or-later.