跪拜 Guibai
← All articles
Android · Gradle · Frontend

AGP 9.0 Forces a New DSL, Built-in Kotlin, and Stricter R8 Rules

By Coffeeee ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This upgrade is a forced march off deprecated APIs with a ticking clock: the opt-out flag vanishes in AGP 10.0. Teams that delay will face a compressed migration window in 2026, while the R8 keep-rule and companion-method changes can silently alter runtime behavior on older API levels.

Summary

AGP 9.0 removes the old `BaseExtension` DSL and requires all variant access to go through `androidComponents.onVariants`. A temporary `newDsl=false` escape hatch exists in `gradle.properties` but disappears in AGP 10.0, expected mid-2026. Kotlin is now built into the plugin at version 2.2.10; projects that need a different KGP version must explicitly disable the built-in support and pin a strict version, with a floor of 2.0.0.

Eighteen Gradle properties flip their defaults. Among the most impactful: `android.useAndroidx` and `android.uniquePackageNames` become true, `android.enableAppCompileTimeRClass` forces a switch-to-if-chain refactor, and `android.r8.strictFullModeForKeepRules` demands explicit constructor keep rules. R8 also gains a `-processkotlinnullchecks` option that can strip null-check messages or remove checks entirely, and keep rules no longer propagate to companion methods, which breaks interface desugaring below API 24.

Several features are gone outright: Wear OS embedded apps, density-split APKs, the `androidDependencies` task, and the `PostProcessing` block. The `CommonExtension` parameterization is removed, pushing block methods into `ApplicationExtension`, `LibraryExtension`, and their peers — a source-level break that touches any custom build logic.

Takeaways
AGP 9.0 requires Gradle 8.1.0, SDK build tools 36.0.0, NDK 28.2.13676358, and caps the target API level at 36.1.
All variant access must switch from `applicationVariants` / `libraryVariants` to `androidComponents.onVariants` and `beforeVariants`.
Setting `android.newDsl=false` in `gradle.properties` restores the old DSL; per-module opt-out arrives in AGP 9.4, and the flag is removed entirely in AGP 10.0.
Kotlin 2.2.10 is bundled and enabled by default; projects needing a different version must set `android.builtInKotlin=false` and declare a strict KGP version, with 2.0.0 as the minimum.
Eighteen Gradle properties flip defaults, including mandatory AndroidX, unique package names, compile-time R class constants, and stricter ProGuard keep rules.
R8's new `-processkotlinnullchecks` option defaults to `remove_message`, rewriting null checks to `getClass()` calls while stripping the message.
Keep rules no longer propagate to synthetic companion methods, which can break interface desugaring when `minSdk < 24`.
Wear OS embedded app support, density-split APKs, the `androidDependencies` task, and the `PostProcessing` block are removed.
`CommonExtension` parameterization is gone; block methods move to `ApplicationExtension`, `LibraryExtension`, `DynamicFeatureExtension`, and `TestExtension`, breaking custom build scripts.
Conclusions

Bundling Kotlin into AGP ends the separate KGP version-management dance but creates a lockstep coupling: an AGP upgrade now drags in a Kotlin compiler upgrade whether the project is ready or not.

The removal of keep-rule propagation to companion methods is a subtle desugaring trap. Projects with `minSdk < 24` that rely on interface keep rules may find methods stripped without a clear build error.

Flipping `android.enableAppCompileTimeRClass` to true by default forces every `switch` on resource IDs to become an `if` chain — a mechanical refactor that touches a lot of code for no functional gain, purely to satisfy the compiler.

The opt-out window is deliberately narrow: AGP 9.0 ships the escape hatch, 9.4 adds per-module control, and 10.0 kills it. Google is signaling that the old DSL is dead and teams should budget the migration now, not in 2026.

Concepts & terms
AGP DSL
The Android Gradle Plugin's domain-specific language for configuring builds. AGP 9.0 replaces the old `BaseExtension`-based DSL with a new public interface accessed through `androidComponents`.
KGP (Kotlin Gradle Plugin)
The plugin that adds Kotlin compilation support to Gradle projects. AGP 9.0 bundles KGP 2.2.10 internally, removing the need to declare it separately unless a different version is required.
R8
Google's default code shrinker and obfuscator for Android, replacing ProGuard. AGP 9.0 tightens its default rules and adds a Kotlin null-check processing option.
Companion method propagation
A previous R8 behavior where keep rules on interface methods automatically applied to synthetic companion methods generated during desugaring. AGP 9.0 stops this propagation, which can cause missing methods on API levels below 24.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗