A template for integrating Rust with Kotlin Multiplatform (KMP) using UniFFI and gobley.
The template provides a complete build pipeline for exposing a Rust crate to Kotlin Multiplatform targets, including JVM, Android, and iOS. The entire workflow is managed through a single justfile.
- JVM
- Android
- iOS
- Linux
- macOS
- Windows
Install the following tools before getting started.
Rust is pinned to version 1.89.0 using rust-toolchain.toml.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shThen install the required cross-compilation targets:
just setup# Fedora / RHEL
sudo dnf install just
# Debian / Ubuntu
sudo apt install just
# macOS
brew install just# Fedora / RHEL
sudo dnf install java-21-openjdk-devel
# Debian / Ubuntu
sudo apt install openjdk-21-jdk
# macOS
brew install openjdk@21Install the required Android SDK platform and NDK:
sdkmanager "platform-tools" \
"platforms;android-36" \
"ndk;30.0.14904198"Set the Android SDK and NDK environment variables:
export ANDROID_SDK_ROOT="$HOME/Android/Sdk"
export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/30.0.14904198"Install cargo-ndk:
cargo install cargo-ndkThese tools are required for Linux and macOS builds.
# Fedora / RHEL
sudo dnf install zig
# Debian / Ubuntu
snap install zig --classic
# macOS
brew install zigThen install cargo-zigbuild:
cargo install cargo-zigbuildThese tools are required for Windows builds.
# Fedora / RHEL
sudo dnf install clang lld cmake llvmInstall cargo-xwin:
cargo install cargo-xwinInstall the Gobley UniFFI binding generator:
cargo install gobley-uniffi-bindgenXcode is required for iOS and macOS builds.
This step is only required on macOS:
xcode-select --installAt minimum, you need:
- Rust
just- JDK 21
gobley-uniffi-bindgen
Once the required tools are installed, run:
just setupThen build the complete project:
justBuild all supported targets, generate Kotlin bindings, and assemble the KMP library.
justBuild the Rust library for the host Linux x86_64 target.
just build-hostRegenerate the Kotlin bindings based on the current Rust API.
just generate-bindingsAssemble the Kotlin Multiplatform library using Gradle.
just build-kmpRun JVM and Android host tests.
just test-kmpRun JVM tests only:
just test-kmp-jvmPublish the KMP library to the local Maven repository.
just publish-localThe library will be available under:
~/.m2
Remove generated build artifacts and outputs.
just cleanTo view all available just recipes:
just --listThe justfile is the central entry point for the build, binding generation, testing, packaging, and publishing workflow.