Skip to content

Building library for Android

Dusko Ojdanic edited this page Aug 16, 2020 · 20 revisions
  • Clone this repo

  • Install rustup

  • Make sure you've the Android NDK installed, and that the android.ndkVersion variable in build.gradle points to it. E.g:

android {
    ...
    ndkVersion "21.3.6528147"
    ...
}
cargo install cargo-ndk
  • Add toolchains:
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android 

The list of targets above is not necessarily up to date. See e.g. here for current targets. Use rustup target list to see a list of currently supported targets.

  • Run the script, which will build the libraries and copy them to the Android local copy:
sh ./android/scripts/make_rust.sh
  • To build and copy a release version pass the --release flag to the script:
sh ./android/scripts/make_rust.sh --release

Creating a new release:

  • Run the Core Android app's Unit and instrumentation tests. Ensure everything is green!
  • Run make_rust.sh with --release TODO fix path to the repo's root. This will overwrite the jniLibs folder under android > core > core > src > main with the release binaries.
  • Zip the jniLibs folder.
  • Create a new Release in Github and attach the zip as binary.

NOTE: You have to attach the iOS binaries as well. Instructions here.

Why are there 2 android projects?

Differently to iOS, on Android the FFI (JNI) requires a lot of boilerplate, so to make things safer (and some historical developments around figuring out how to bundle core as external dependency, which was less straight forward than for iOS), we decided to move the JNI mappings to a "core" Android library. This way we can focus on providing a safe, well tested and easy to use interface to the "frontend" app.

Ideally iOS would have something similar, as the FFI there is still error prone, but this seems overkill at the moment.

Clone this wiki locally