Using the Gradle plugins
This project contains three Gradle plugins:
- The Cargo plugin (
dev.lidory.rustine.cargo) - The UniFFI plugin (
dev.lidory.rustine.uniffi) - The Rust plugin (
dev.lidory.rustine.rust)
These plugins are published in Maven Central. In your settings.gradle.kts, put mavenCentral() in
the pluginManagement {} block.
pluginManagement {
repositories {
mavenCentral()
}
}
If you're using multi-project builds, please read The Rust plugin.
Requirements
The plugins require Gradle 8.11 or higher and JDK 17 or higher. The Rust crates require Rust 1.88 or higher, and must depend on the UniFFI version targeted by the bindgen, which is UniFFI 0.32.2 for Rustine 1.0.0 (see Versioning). To use the plugins in Android projects, you need:
- Android Gradle Plugin (AGP) 9.1 or higher. AGP 8 is not supported anymore. If your project still uses AGP 8, please use Gobley 0.3.7 or older.
- Gradle 9.3.1 or higher, which is required by AGP 9.1.
- JDK 17 or higher.
- Kotlin 2.4.0 or higher is recommended, as it is the first version of the Kotlin Gradle plugin officially supporting AGP 9.1.
AGP 9.1 uses Android SDK Build-Tools 36.0.0 and NDK 28.2.13676358 (r28c) by default.
The plugins support the following two kinds of Android modules. The plugins can be applied before or after the Android Gradle plugin.
-
com.android.applicationorcom.android.librarymodules using the built-in Kotlin support of AGP. Don't apply theorg.jetbrains.kotlin.androidplugin.plugins {
id("com.android.application") // or id("com.android.library")
id("dev.lidory.rustine.cargo")
id("dev.lidory.rustine.uniffi")
kotlin("plugin.atomicfu")
} -
Kotlin Multiplatform modules using the Android-KMP library plugin (
com.android.kotlin.multiplatform.library). The Android target is configured in thekotlin { android {} }block.plugins {
kotlin("multiplatform")
id("com.android.kotlin.multiplatform.library")
id("dev.lidory.rustine.cargo")
id("dev.lidory.rustine.uniffi")
kotlin("plugin.atomicfu")
}
kotlin {
android {
namespace = "com.example.mylibrary"
compileSdk = 36
minSdk = 24
}
}The experimental
android.kmp.use.jvm.platform.type=trueGradle property is not supported.
Migrating to AGP 9
AGP 9 no longer supports some of the project setups that Gobley 0.3.7 and older supported. Please read the official migration guides from Google and JetBrains first. Rustine-specific changes are as follows.
-
Remove
org.jetbrains.kotlin.android. AGP 9 compiles Kotlin by itself and rejects theorg.jetbrains.kotlin.androidplugin. Rustine doesn't support theandroid.builtInKotlin=falseandandroid.newDsl=falseopt-out properties. -
Use AGP configurations instead of Kotlin source sets in Android modules. Built-in Kotlin doesn't provide
kotlin.sourceSets. Declare dependencies in the top-leveldependencies {}block using configurations liketestImplementationorandroidTestImplementation.// Before
kotlin {
sourceSets {
getByName("test") {
dependencies {
implementation(libs.junit)
}
}
}
}
// After
dependencies {
testImplementation(libs.junit)
} -
Replace
androidTarget()withcom.android.kotlin.multiplatform.library. A Kotlin Multiplatform module can't applycom.android.applicationorcom.android.libraryanymore. Applycom.android.kotlin.multiplatform.libraryand move the settings in theandroid {}block intokotlin { android {} }. If the module was an Android application, move the application part (applicationId,targetSdk, the activities, signing configs, etc.) to a separatecom.android.applicationmodule that depends on the Kotlin Multiplatform module.// Before
plugins {
kotlin("multiplatform")
id("com.android.library")
// ...
}
kotlin {
androidTarget()
}
android {
namespace = "com.example.mylibrary"
compileSdk = 36
defaultConfig {
minSdk = 24
}
}
// After
plugins {
kotlin("multiplatform")
id("com.android.kotlin.multiplatform.library")
// ...
}
kotlin {
android {
namespace = "com.example.mylibrary"
compileSdk = 36
minSdk = 24
}
} -
Replace
androidUnitTestwithandroidHostTest. Local unit tests of Kotlin Multiplatform libraries are in theandroidHostTestsource set, which exists only when you enable host tests usingkotlin { android { withHostTest {} } }. -
Choose the Cargo profile of Kotlin Multiplatform libraries using
androidVariant.com.android.kotlin.multiplatform.libraryhas no build types, so Rustine embeds the variant selected bycargo.androidVariant. It defaults toVariant.Releasewhen the requested tasks look like release builds or publishing (e.g.,assembleRelease,bundleRelease, orpublish), and toVariant.Debugotherwise. Set it explicitly when you build a release version of your app in another way, e.g., with./gradlew build. See Be careful of the build variant used during publishing. -
Don't call Rust functions from Compose previews in Kotlin Multiplatform libraries. Rustine adds the Rust library for the host to the debug variant of
com.android.applicationandcom.android.librarymodules during IDE sync, so that Compose previews can call Rust functions.com.android.kotlin.multiplatform.libraryhas no debug variant, so Compose previews in these libraries can't call Rust functions. -
Use
embedRustLibraryto exclude ABIs in Kotlin Multiplatform libraries.com.android.kotlin.multiplatform.libraryhas nondk.abiFilters. See Building for Android. -
Update references to the generated ProGuard rule file. The file generated by the UniFFI plugin moved from
build/generated/uniffi/androidMain/generated-proguard-rules.txttobuild/generated/uniffiProguardRules/generated-proguard-rules.txt. It is added to your Android modules automatically, so you don't have to reference it unless you have your own build logic using that file.