ANDROID_HOME=C:\Users\USER\AppData\Local\Android\Sdk NDK_PATH=$ANDROID_HOME/ndk/26.1.10909125 # .cargo/config [target.x86_64-linux-android] linker = "C:/Users/USER/AppData/Local/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/windows-x86_64/bin/x86_64-linux-android24-clang.cmd" [target.i686-linux-android] linker = "C:/Users/USER/AppData/Local/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/windows-x86_64/bin/i686-linux-android24-clang.cmd" [target.armv7-linux-androideabi] linker = "C:/Users/USER/AppData/Local/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/windows-x86_64/bin/armv7a-linux-androideabi24-clang.cmd" [target.aarch64-linux-android] linker = "C:/Users/USER/AppData/Local/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android24-clang.cmd" # add toolchains rustup target add \ x86_64-linux-android \ i686-linux-android \ armv7-linux-androideabi \ aarch64-linux-android # generate library cargo new reverse-rs --lib # reverse-rs/Cargo.toml [package] name = "reverse-rs" version = "0.1.0" edition = "2021" [lib] name = "reverse" crate-type = ["cdylib"] [dependencies] uniffi = { version = "0.23.0" } [build-dependencies] uniffi = { version = "0.23.0", features = [ "build" ] } // reverse-rs/src/reverse.udl namespace reverse { string reverse_string([ByRef] string input_string); i32 reverse_integer(i32 input_integer); }; # reverse-rs/build.rs fn main() { uniffi::generate_scaffolding("./src/reverse.udl").unwrap(); } # reverse-rs/src/lib.rs uniffi::include_scaffolding!("reverse"); pub fn reverse_string(input_string: &str) -> String { // ... # build libs cargo build --lib \ --target x86_64-linux-android \ --target i686-linux-android \ --target armv7-linux-androideabi \ --target aarch64-linux-android # rename all libs reverse-rs/ ❯ tree jniLibs jniLibs ├── arm64-v8a │ └── libuniffi_reverse.so ├── armeabi-v7a │ └── libuniffi_reverse.so ├── x86 │ └── libuniffi_reverse.so └── x86_64 └── libuniffi_reverse.so # reverse-rs/Cargo.toml # ... [[bin]] name = "uniffi-bindgen" path = "uniffi-bindgen.rs" # reverse-rs/uniffi-bindgen.rs fn main() { uniffi::uniffi_bindgen_main() } # generate kotlin bindings cargo run --features=uniffi/cli \ --bin uniffi-bindgen \ generate src/reverse.udl \ --language kotlin # Create android library // reverse-android/app/build.gradle // ... dependencies { // ... implementation "net.java.dev.jna:jna:5.13.0@aar" // ... } # Add libs and generated files