Skip to content

Require Android Gradle Plugin 9 and Gradle 9.1 - #177

Merged
rvandermeulen merged 4 commits into
mozilla:masterfrom
rvandermeulen:agp-9
Nov 16, 2026
Merged

rvandermeulen merged 4 commits into
mozilla:masterfrom
rvandermeulen:agp-9

Conversation

@rvandermeulen

Copy link
Copy Markdown
Collaborator

AGP 9 removed BaseExtension, AppExtension and LibraryExtension, which the plugin used to configure itself, so this ports it to the androidComponents API. The plugin now requires AGP 9.0 or newer and Gradle 9.1 or newer. Projects still on AGP 8 can stay on 0.10.0.

Behavior changes for consumers:

  • Each variant's jniLibs merge and unit test tasks now depend on cargoBuild, so the Rust libraries are always built before they are packaged or loaded in unit tests. Builds no longer need their own dependsOn 'cargoBuild' hook.
  • When apiLevel/apiLevels aren't set, the default API level is the lowest minSdk across the variants, not defaultConfig.minSdk.
  • Desktop libraries now go on each unit test task's classpath instead of the unit test Java resources. AGP leaves .so files out of unit test Java resources, so desktop libraries now also load in unit tests on Linux hosts.
  • RUST_ANDROID_GRADLE_TARGET_* properties are read from the project's extra properties, since Project.getProperties fails in Gradle 10. Gradle properties from every source still work, including a subproject's gradle.properties. A value set with ext in a parent project is no longer inherited; it has to be set in the project that applies the plugin, or through allprojects.
  • The jniLibs directory is added per variant, so it no longer appears in android.sourceSets.main.jniLibs.
  • generateLinkerWrapper is a plain Sync task, and the GenerateLinkerWrapperTask class is gone.

The build moves to Gradle 9.9.1 and Kotlin 2.4, still targeting the Kotlin 2.2 API (what Gradle 9.1 embeds) and Java 17 bytecode. CI moves to JDK 25 and NDK r30.

Tests:

  • The test matrix covers AGP 9.0.0 on Gradle 9.1.0 and AGP 9.5.1 on Gradle 9.9.1.
  • The new CargoEnvironmentTest covers target property passthrough, API level selection and the unit test classpath.
  • CargoTargetTest builds the linux-x86-64 desktop target on Linux.
  • CargoBuildTest runs only mergeDebugJniLibFolders and checks that it pulls in cargoBuild.
  • All three samples are ported without build hooks, and CI now runs the samples/unittest unit tests on Linux.

The README gets the AGP 9 requirement and corrected RUST_ANDROID_GRADLE_TARGET_ examples, and drops the javaPreCompile hook it used to suggest, which never ordered cargoBuild before the merge.

Fixes #43, fixes #85, fixes #166. This likely also addresses #118 and #147, which report the same task-ordering symptoms on older AGP versions.

@segunfamisa segunfamisa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this patch. It's my first review on this project, so I may be missing a lot of context, but this looks and reads correct to me.

I had only one minor and optional feedback comment.

AGP 9 no longer exposes BaseExtension, AppExtension or LibraryExtension, which the plugin configured through,
so it now uses the androidComponents API: the default API level is the lowest minSdk of the variants, the
jniLibs directory is added per variant, and the NDK directory comes from sdkComponents. Each variant's jniLibs
merge and unit test tasks depend on cargoBuild, so changed Rust code always reaches the merged libraries
without a hook in the consuming build (mozilla#166); the README drops the javaPreCompile hook it used to suggest,
which never ordered cargoBuild before the merge. The desktop libraries go on each unit test task's classpath
instead of the unit test Java resources, which AGP builds without .so files, so they now load on Linux hosts
too. Per-target RUST_ANDROID_GRADLE_TARGET_ properties are read from the project's extra properties, since
Project.getProperties fails in Gradle 10 and the providers API skips subproject gradle.properties and ext
values. Values inherited from a parent project's ext are no longer read, matching Gradle's deprecation of that
lookup, and the README says where an ext value has to go. The generateLinkerWrapper task is a plain Sync.
Projects still on AGP 8 can stay on 0.10.0.

The plugin compiles against the AGP 9.0.0 API with Kotlin 2.4 at the Kotlin 2.2 language and API level that
Gradle 9.1 embeds, and still emits Java 17 bytecode. The build moves to Gradle 9.9.1, Spock 2.5 for Groovy 4
and current plugin-publish and test-retry. The version helpers used the removed org.gradle.util.VersionNumber
and only serve the tests, so they move there with their Guava dependency, which the published plugin no longer
carries.

The test matrix covers AGP 9.0.0 on Gradle 9.1.0 and AGP 9.5.1 on Gradle 9.9.1, the test projects build
against compileSdk 36 and NDK r30, CargoBuildTest now checks that merging the jniLibs runs cargoBuild and
picks up the libraries, and pins the per-target task names, and CargoTargetTest builds the linux-x86-64
desktop target on Linux hosts. The README's cargo argument examples gain the TARGET_ prefix the plugin
matches.
The applicationVariants and libraryVariants hooks go, since the plugin now orders cargoBuild before the
jniLibs merge and unit tests. The release build types only restated the defaults and named
proguard-android.txt, which AGP 9 rejects, so they go, along with the unused proguard-rules.pro. The samples
build against compileSdk 36 and NDK r30.

samples/unittest drops its Gradle 6.1.1 wrapper for the top-level one the other samples use, and moves to
Robolectric 4.17 for SDK 36 with the JUnit 4.13.2 it requires.
The jobs installed NDK r21 and r23, which no test uses. The tests now default to r30. NdkVersionTest drops
r28, which the Ubuntu and Windows runner images no longer carry, and covers r27, r29 and r30. The samples job
also runs the samples/unittest unit tests on Linux.
CargoEnvironmentTest runs in the AGP version matrix and records cargo's environment through a RUSTC_WRAPPER
passed in as a target property.
@rvandermeulen
rvandermeulen merged commit 3e0a93e into mozilla:master Nov 16, 2026
13 checks passed
@rvandermeulen
rvandermeulen deleted the agp-9 branch November 16, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants