AGP 9.0 Upgrade Hits Three Breaking Changes: Built-in Kotlin, Gradle 9.5, and JVM 11
Android AGP 9.0 Upgrade Journey
1. Foreword:
Recently upgraded Android Studio to 9.0, but found quite a few issues. Having gained a lot of experience and stepped on many pitfalls during previous upgrades to 7.0 and 8.0, this upgrade went very smoothly. If you are on a version below 7.0, direct upgrade is not recommended, but of course, if you are experienced, it doesn't matter. Let's go straight to the code.
Official reference documentation:
https://developer.android.google.cn/build/releases/agp-9-0-0-release-notes?hl=hr
2. Introduction:
Android Gradle plugin 9.0 is a major release that brings API and behavioral changes.
To update to Android Gradle plugin 9.0.1, use the Android Gradle plugin Upgrade Assistant. The AGP Upgrade Assistant helps preserve existing behavior as much as possible when upgrading a project, so you can upgrade your project to use AGP 9.0 even if you are not yet ready to adopt all the new defaults in AGP 9.0.
Additionally, two agent skills are available to simplify the upgrade process. For non-KMP apps, try the AGP 9 Upgrade Skill from the Android Skills library. For KMP apps, try JetBrains' AGP 9 Upgrade Skill. For more details on using skills in Android Studio, see Extending Agent Mode with Skills.
3. Compatibility
Android Gradle plugin 9.0 supports a maximum API level of API level 36.1. Below is more compatibility information:
| Minimum Version | Default Version | Notes | |
|---|---|---|---|
| Gradle | 9.1.0 | 9.1.0 | For details, see Update Gradle. |
| SDK Build Tools | 36.0.0 | 36.0.0 | Install or configure SDK Build Tools. |
| NDK | N/A | 28.2.13676358 | Install or configure another version of NDK. |
| JDK | 17 | 17 | For details, see Set JDK Version. |
4. Upgrading AGP Version to 9.3.1:
My starting version was 8.9.3
Upgraded to 9.3.1:
[versions]
agp = "9.3.1"
org-jetbrains-kotlin-android = "1.8.0"
core-ktx = "1.15.0"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
appcompat = "1.6.1"
material = "1.13.0"
constraintlayout = "2.1.4"
glide = "4.13.0"
glide-compiler = "4.13.0"
camerax = "1.1.0-beta03"
camerax-core = "1.1.0-beta03"
camerax-video = "1.1.0-beta03"
camerax-view = "1.1.0-beta03"
camerax-extensions = "1.2.2"
camerax-lifecycle = "1.1.0-beta03"
kotlin-stdlib = "1.8.0"
kotlin-reflect = "1.8.0"
kotlinx-coroutines-core = "1.8.0"
kotlinx-coroutines-android = "1.8.0"
utilcodex = "1.31.1"
activity= "1.12.0"
5. Error: Gradle Plugin Version Too Low:
Prompted to change the Gradle plugin to 9.5.0; the current one is 8.11.1
Modified configuration:
#Sun Aug 23 15:17:09 CST 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-9.5.0-bin.zip
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6. Error: Duplicate Kotlin Import:
Build file 'D:\workspace\camera-xdemo\app\build.gradle.kts' line: 4
An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.android', version: '1.8.0']
> Failed to apply plugin 'org.jetbrains.kotlin.android'.
> Cannot add extension with name 'kotlin', as there is an extension already registered with that name.
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights from a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.
* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.android', version: '1.8.0']
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:184)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$ApplyAction.apply(DefaultPluginRequestApplicator.java:165)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$applyPlugins$1(DefaultPluginRequestApplicator.java:135)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:135)
at org.gradle.kotlin.dsl.provider.PluginRequestsHandler.handle(PluginRequestsHandler.kt:45)
at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost.applyPluginsTo(KotlinScriptEvaluator.kt:246)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.applyPluginsTo(Interpreter.kt:399)
at Program.execute(Unknown Source)
Built-in Kotlin
Android Gradle plugin 9.0 introduces built-in Kotlin support and enables it by default. This means you no longer need to apply the org.jetbrains.kotlin.android (or kotlin-android) plugin in your build files to compile Kotlin source files. This simplifies Kotlin integration with AGP, avoids using deprecated APIs, and improves performance in some cases.
Therefore, when you upgrade your project to AGP 9.0, you also need to migrate to built-in Kotlin or choose to opt out.
You can also selectively disable built-in Kotlin support for Gradle subprojects that have no Kotlin source.
7. Modifications as Follows:
Remove the Kotlin configuration from the app directory's build.gradle and the project's build.gradle respectively.
import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled.enabled
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.com.android.application)
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.com.android.application) apply false
}
true
Remove the kotlin-android configuration from libs.versions.toml:
[plugins]
com-android-application = { id = "com.android.application", version.ref = "agp" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "org-jetbrains-kotlin-android" }
8. Modifying JVM Configuration in Kotlin:
Configuration before modification:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
Configuration after modification:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}
9. Running After Modification:
As you can see, after the modification, the project built successfully and runs normally.
10. Screenshot of Running Effect:
11. Complete Demo Address:
https://gitee.com/jackning_admin/camera-xdemo
12. Complete Pitfall Checklist Review for This Upgrade:
- AGP 9.3.1 → Gradle version insufficient (8.11.1), upgrade Gradle wrapper to 9.5.0
Cannot add extension with name 'kotlin'→ AGP has built-in Kotlin, duplicate loading of kotlin-android pluginUnresolved reference kotlinOptions→ DSL change, switch tokotlin{compilerOptions{}}- Invalid garbage import
import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled.enabled, delete directly - Java bytecode version upgrade from 1.8 → 11
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
Does the Android Studio version have any requirements?