Introduction: Example of compiling a Rust library into an Android app
More: Author   ReportBugs   

This repository is a demonstration of an Android app integrating a native Rust library. Additionally, this Rust library demonstrates detecting support for SIMD instructions.

You can find more information in the following blog posts:


To build a Docker container containing all the build tools and the demo application, run:

$ sudo ./

Building and running the demo Android application

You can then launch this Docker container to build the application. This comes in various configurations:

  • minimal setup to compile the application within the container.
  • besides compiling the application, this setup allows to spawn an Android emulator within the container to test this application.
  • besides compiling the application, this setup gives the container access to the USB devices, so that you can install the application on a real device via ADB.
  • setup with everything available in the container.
$ sudo ./
$ ./ && ./

You can build various flavors of the Rust library.

  • basic script using the nightly Rust toolchain, with stripping of debug symbols enabled.
  • same, but without stripping debug symbols.
  • and using a locally built stage1 Rust compiler (see below).
  • and using the default Rust toolchain (stable).
  • more advanced library, which bundles another library linked twice (see the corresponding blog post).

Then, multiple ways are provided to build the Java part of the Android app.

  • normal build of the Android app.
  • Android app built with the ARM-64 library in the wrong folder.
  • Android app built with the x86_64 library in the wrong folder.

You can then spawn an Android emulator with, and use the or scripts to install+launch the application via ADB to either the emulator or a real device connected via USB.

Building and using a patched Rust compiler

This repository also shows how to patch and build the Rust compiler. You can launch the Docker container in various scenarios:

  • with 1 CPU, 2 GB of RAM,
  • with 2 CPUs, 2 GB of RAM,
  • with 4 CPUs, 3 GB of RAM,
  • with 8 CPUs, 5 GB of RAM,
  • to compile rustc + build the app.

Once launched, you can clone and compile rustc for Android with:

  • scripts/ clone the latest commit on the Rust repository,
  • scripts/ build a stage 0 compiler,
  • scripts/ build a stage 1 compiler.

You'll also find the following tool to generate a flame graph of the disk space used by a build of rustc:

  • tools/flamedisk: small Rust tool to generate an input suitable for,
  • scripts/ driver script to generate the flame graph.

Running unit tests and benchmarks on an Android device

This repository shows how to run Rust unit tests and benchmarks directly on an attached Android device (physical device via USB or emulator), without using a full Android application. The script tells Cargo how to do that.

Within the Docker container, you can run the following benchmarks:

About Me
GitHub: Trinea
Facebook: Dev Tools