Cross compiling armv7-linux-androideabi using Rust

hc
2 min readDec 9, 2021

--

I spent the whole day trying to cross compile on a x86 Ubuntu to a armv7-linux-androideabi but failed.

Then I remembered about cross which boasted it could cross compile magically. I was skeptical. But I thought maybe it’ll work… and I tried it.

The setup was easy. Install cross using the following command and have docker on your system — which I already had.

cargo install cross

Next, they provided some examples to cross compile like building on a aarch64.

cross build --target aarch64-unknown-linux-gnu

So I tried the following command to build for an armv7 android device.

cross build --target armv7-linux-androideabi

There was some errors building Openssl… but after so many searching on google the whole day I tried adding the vendored flag in the feature in the Cargo.toml.

[dependencies]
tokio-tungstenite = "*"
tokio = { version = "1.14.0", features = ["full"] }
reqwest = { version = "0.11.6", features = ["json"] }
serde = { version = "1.0.130", features = ["derive"] }
url = "2.2.2"
futures-util = "0.3.18"
futures-channel = "0.3.18"
openssl = { version = "0.10", features = ["vendored"] }

It WORKED. The build succeeded. Checking the file we can see that it is dynamically linked. I copied the file to the android device and ran it using termux.

ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, with debug_info, not stripped

Viola! It worked! It’s magic. No more downloading of custom gcc linkers manually. Everything handled using a docker container.

To find the targets available for cross compilation, see the link below. Under Tier 2, there is a table which shows all the available targets.

https://doc.rust-lang.org/nightly/rustc/platform-support.html

--

--

No responses yet