- Install Java Runtime Environment, for example
openjdk-jre
. - Download Android SDK Command line tools for your platform.
- Unpack
cmdline-tools
and put it to theandroid-sdk
directory. WARNING! Make location to the content of the tools archive asandroid-sdk/cmdline-tools/latest/
. - Setup
ANDROID_SDK_ROOT
env variable to theandroid-sdk
location and add theandroid-sdk/cmdline-tools/latest/bin/
to thePATH
env variable. - Install SDK components:
$ sdkmanager "ndk;23.1.7779620" "platforms;android-23" "platform-tools" "build-tools;32.0.0"
- Setup
ANDROID_NDK_ROOT
env variable to the$ANDROID_SDK_ROOT/ndk/23.1.7779620/
location. - Add necessary build targets:
$ rustup target add --toolchain stable aarch64-linux-android
$ rustup target add --toolchain stable i686-linux-android
- Install
cargo-apk
tool and build project:
$ cargo install cargo-apk
$ cargo +stable apk build --lib --release
WARNING! If you get an error like this:
= note: ld: error: unable to find library -lgcc
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
Then patch your toolchain libraries with:
$ echo 'INPUT(-lunwind)' > ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-linux-android/lib/libgcc.a