How should I compile Rust for Android in 2021?

Viewed 1970

This tutorial by Mozilla explains how to generate standalone toolchains for Rust doing

mkdir NDK
${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir NDK/arm64
${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm --install-dir NDK/arm
${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch x86 --install-dir NDK/x86

These are needed mostly for ar and linker if I understood correctly. clang++ of course won't be used.

But this tutorial is old and according to https://developer.android.com/ndk/guides/standalone_toolchain, this script is obsolte. It says As of r19, the NDK's default toolchains are standalone toolchains, which renders this process unnecessary.

I think that I should just point my cargo-config.toml locations to this instead.

However, is it the right way to compile for Android in 2021?

1 Answers

Forget everything from the mozilla blog. You should use now this gradle plugin that integrates with cargo gracefully: https://github.com/mozilla/rust-android-gradle

No need to do anything from the blog post, just follow the readme on this repo

Related