How to make an Android NDK shared library with Rust?


Hi,I want to write a shared library to boost the performance of my Android project,Can someone give an example how to write a shared library in Rust?Thanks。



First create a new project in Cargo (cargo new test_sharedlib) Modify the Cargo.toml file and add the following lines

   name = "mylib"
   crate-type = ["dylib"]

Run cargo build and you should now see a file in target/debug/ being called something like depending on your platform.

Now in your src/ you likely want some entry symbol/data so you will need to mark that like this

 pub fn call_me() {

Hopefully that should get you going.



Android is running on different architectures, including ARM, Intel Atom, etc.

You have to cross compile your program for every arch.

Everything you need to know about cross compiling Rust programs!