#ndk #cargo #android #build

app cargo-ndk

Makes building Rust libraries for Android simpler

19 releases (7 stable)

new 2.4.1 Jul 19, 2021
2.2.0 Feb 2, 2021
1.0.0 Mar 15, 2020
0.6.2 Mar 5, 2020
0.1.3 Jul 22, 2018

#4 in Cargo plugins

Download history 454/week @ 2021-04-04 644/week @ 2021-04-11 395/week @ 2021-04-18 395/week @ 2021-04-25 454/week @ 2021-05-02 571/week @ 2021-05-09 487/week @ 2021-05-16 475/week @ 2021-05-23 341/week @ 2021-05-30 425/week @ 2021-06-06 613/week @ 2021-06-13 446/week @ 2021-06-20 504/week @ 2021-06-27 480/week @ 2021-07-04 422/week @ 2021-07-11 450/week @ 2021-07-18

1,935 downloads per month

Apache-2.0 OR MIT

20KB
464 lines

cargo-ndk - Build Rust code for Android

This cargo extension handles all the environment configuration needed for successfully building libraries for Android from a Rust codebase, with support for generating the correct jniLibs directory structure.

Installing

cargo install cargo-ndk

You'll also need to install all the toolchains you intend to use. Simplest way is with the following:

rustup target add \
    aarch64-linux-android \
    armv7-linux-androideabi \
    x86_64-linux-android \
    i686-linux-android

Modify as necessary for your use case.

Usage

If you have installed the NDK with Android Studio to its default location, cargo ndk will automatically detect the most recent NDK version and use it. This can be overriden by specifying the path to the NDK root directory in the ANDROID_NDK_HOME environment variable.

Example: building a library for 32-bit and 64-bit ARM systems

cargo ndk -t armeabi-v7a -t arm64-v8a -o ./jniLibs build --release 

This specifies the Android targets to be built, the output directory to use for placing the .so files in the layout expected by Android, and then the ordinary flags to be passed to cargo.

Example

Supported hosts

  • Linux
  • macOS (x86_64 and arm64)
  • Windows

Similar projects

  • cargo-lipo - for building iOS universal Rust libraries

License

This project is licensed under either of

at your option.


Uyghurs are under attack in Xinjiang. The Chinese government is placing millions of people into indoctrination camps and engaging in forced labour.

Dependencies

~3–4.5MB
~107K SLoC