cargo-android is a bare-bones, no dependency wrapper around cargo
that sets up the necessary environment variables to cross-compile for Android.
-
Install cargo-android.
cargo install --git https://github.com/chenxiaolong/cargo-android
-
Install the Android Rust target. This requires Rust to be installed via rustup because most other distributions do not package the Android targets.
rustup target add aarch64-linux-android
-
Set the
ANDROID_NDK_ROOT
environment variable to the path of the Android NDK toolchain. -
Set the
ANDROID_API
environment variable to the desired API level (eg. Android 14 is API 34). If left unset, the latest API level supported by the NDK toolchain will be used. Executables compiled for old Android versions can run on newer Android versions, but the reverse is not always true. -
Run
cargo
commands by prefixing the subcommand withandroid
. For example:cargo build --target aarch64-linux-android --release
would become:
cargo android build --target aarch64-linux-android --release
If
--target
is not specified or if the target is not an Android target, then the wrapper just runs cargo as-is, without setting any environment variables.
Bug fixes are welcome! However, I'm unlikely to accept changes for supporting additional features or configuration that I don't need for my personal projects.
cargo-android is licensed under GPLv3. Please see LICENSE
for the full license text.