A minimal Android app with native Rust code via JNI.
- Kotlin + Jetpack Compose — UI & app logic
- Rust (via
cargo-ndk) — native.solibraries loaded through JNI - Gradle KTS — build system with a custom
build_rusttask
Rust code lives in app/src/main/jni/ and compiles into shared libraries (.so) for four Android architectures:
arm64-v8a, armeabi-v7a, x86, x86_64.
The Gradle task build_rust runs automatically before every build via preBuild, placing the compiled .so files into app/src/main/jniLibs/. On the Kotlin side, the library is loaded with System.loadLibrary("spark_rust") and native functions are declared as external fun.
- Install Rust Android targets:
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android - Make sure
cargo-ndkis installed (the build task auto-installs it if missing). - Open the project in Android Studio and hit Run.
app/
├── src/main/
│ ├── jni/ # Rust crate
│ │ ├── Cargo.toml
│ │ └── src/lib.rs
│ ├── jniLibs/ # compiled .so output (auto-generated)
│ ├── kotlin/ # Kotlin sources
│ └── res/ # Android resources
└── build.gradle.kts # includes build_rust task