1# Android native cross-compilation
2
3`cargo.sh` builds the ARM64 Rust half with an explicitly installed Android NDK
4and Android API level. Run it from the checkout root. It does not install
5tools, accept licenses, change the
6SDK, or require Java.
7
8```sh
9rustup target add aarch64-linux-android
10ANDROID_NDK_HOME=/path/to/android-ndk-r30 \
11 CARGO_BUILD_JOBS=2 platform/android/cargo.sh 24 check -p mobile
12ANDROID_NDK_HOME=/path/to/android-ndk-r30 \
13 CARGO_BUILD_JOBS=2 platform/android/cargo.sh 24 build -p mobile
14```
15
16API 24 here is a cross-compilation test target; the app's minimum supported
17Android version is not decided by this lane. The chosen NDK must supply
18`aarch64-linux-android<API>-clang`. macOS uses the NDK's universal
19`darwin-x86_64` tools; x86_64 Linux uses `linux-x86_64`.
20
21The native static library is `target/android/aarch64-linux-android/debug/libmobile.a`
22(or `release/libmobile.a` with `--release`). `CARGO_TARGET_DIR` can select another
23shared build cache. Clean local package artifacts with `tools/cargo_fresh.py`
24before verifying a different checkout against that cache.
25
26This lane checks and builds native code. `apps/android/build.py` builds the app on it:
27it links the shared library with the same NDK, checks its alignment for 16 KB
28page-size devices, and packages and signs the APK.
29
30Tool selection and prerequisite failures can be checked without an NDK:
31
32```sh
33python3 -m unittest discover -s tools -p 'test_android_toolchain.py'
34```
35
36NDK compiler conventions:
37https://developer.android.com/ndk/guides/other_build_systems