Because the std crate is not prebuilt in ONDK, you must build it along with your project using the -Z build-std flag. You also need to explicitly point Cargo to the NDK linker via the CARGO_TARGET_<TARGET>_LINKER environment variable.
To build a project targeting API 21 for ARM64, follow this pattern:
- Set
LLVM_BIN to the path of the ONDK LLVM prebuilt binaries. - Export the
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER environment variable pointing to the specific clang executable (e.g., aarch64-linux-android21-clang). - Run
cargo build with the -Z build-std flag and the appropriate --target.
Note: You can also configure the linker in your config.toml instead of using environment variables.
LLVM_BIN="<ondk>/toolchains/llvm/prebuilt/<os>-x86_64/bin"
# We need to tell cargo where to find the NDK linker for Android.
# You can also set this in config.toml, check the official documentation.
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$LLVM_BIN/aarch64-linux-android21-clang"
# Finally, build our project with -Z build-std
cargo build -Z build-std --target aarch64-linux-android