This repo was inspired by https://www.reddit.com/r/rust/comments/17dr46y/comment/k60o3is/
It is an attempt to create minimal scaffold to generate android APK's
without using the gradle
build sytem, which is generally used by tools like
xbuild
(NiklasEi's version),
cargo-mobile
/cargo-mobile2
, and the like.
- A working android build system. You can chose to use Android Studio or go the
command-line route to install the needed tools, using eg
sdkmanager
. - A working rust build system with the required targets installed. I
recommend
rustup
to get this setup. - a
.cargo/config.toml
that correctly sets up the linker see the next section
Ideally in the future we can generate this using the env vars.
[target.aarch64-linux-android]
linker = "<ANDROID_HOME>/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
rustflags = [
"-Clink-arg=-landroid",
"-Clink-arg=-llog",
"-Clink-arg=-lOpenSLES",
"-C", "strip=symbols",
]
[target.armv7-linux-androideabi]
linker = "<ANDROID_HOME>/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
rustflags = [
"-Clink-arg=-landroid",
"-Clink-arg=-llog",
"-Clink-arg=-lOpenSLES",
"-C", "strip=symbols",
]
[target.i686-linux-android]
linker = "<ANDROID_HOME>/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android24-clang"
rustflags = [
"-Clink-arg=-landroid",
"-Clink-arg=-llog",
"-Clink-arg=-lOpenSLES",
"-C", "strip=symbols",
]
[target.x86_64-linux-android]
linker = "<ANDROID_HOME>/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android24-clang"
rustflags = [
"-Clink-arg=-landroid",
"-Clink-arg=-llog",
"-Clink-arg=-lOpenSLES",
"-C", "strip=symbols",
]
cargo ndk
to build.so
s for the architectures you want to supportaapt2
to prepare the files to include in your APK and then zip them into an APK filezipalign
to align the archive structureapksigner
to sign with your key
Note; in principle, we can probably even remove aapt2
and zipalign
,
as aapt2
can be essentially replaced by zip
, and zipalaign
is optional.
However, as we do need apksigner
(AFAIK), there doesn't seem to be much
point in removing the other android build tools.