AGP 9 marks the android block as deprecated or fails on BaseExtension
deprecation warnings on the android block after upgrading to AGP 9.0Short answer
AGP 9.0 uses only the new public DSL interfaces. The android block is reported as deprecated only when the project opts out with android.newDsl=false, which brings back the old classes. Remove the opt-out, replace applicationVariants with androidComponents, drop the kotlin-android plugin, and update plugins that still use BaseExtension.
Fix it fast
1Find out which cause you have
Look for opt-out switches in gradle.properties. They explain why the old classes (and the warnings) are present.
grep -n "android\.\(newDsl\|builtInKotlin\)" gradle.properties2Match what you see, then jump to its fix
- 1
gradle.properties contains android.newDsl=false and the build shows deprecation warnings, including on the android blockandroid.newDsl=false is set, so the old deprecated classes are still usedFix - 2
ClassCastException with BaseExtension, or a script reading applicationVariants, libraryVariants or variantFilterBuild logic still uses applicationVariants or other removed variant APIFix - 3
Failed to apply plugin 'org.jetbrains.kotlin.android'. ... no longer required for Kotlin support since AGP 9.0The kotlin-android plugin is still appliedFix
- 1
What does the error look like?
deprecation warnings on the android block after upgrading to AGP 9.0java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtensionFailed to apply plugin 'org.jetbrains.kotlin.android'.
Cause 1 of 3
android.newDsl=false is set, so the old deprecated classes are still used
1Check
AGP 9.0 switches to the new DSL interfaces by default. Projects that opt out with android.newDsl=false get the old implementations back, marked as deprecated, which is where the warnings come from. The opt-out is documented to be removed in AGP 10.0.
cat gradle.properties2Fix
Remove the line (or set it to true) once your own build logic and plugins are ready, and fix what then fails. Until then the warnings are expected.
# gradle.properties
# android.newDsl=false <- delete this line3Verify
Run a build and read the output for remaining warnings.
./gradlew assembleDebugConfirmed by developer.android.com
Cause 2 of 3
Build logic still uses applicationVariants or other removed variant API
1Check
With the new DSL the old variant API is no longer accessible. The release notes list applicationVariants, libraryVariants, testVariants, unitTestVariants and variantFilter as affected, with androidComponents replacements.
grep -rn -E "applicationVariants|libraryVariants|variantFilter|BaseExtension" --include=*.gradle --include=*.gradle.kts --include=*.kt .2Fix
Replace applicationVariants and the similar calls with androidComponents.onVariants, and variantFilter with androidComponents.beforeVariants. If a third-party plugin is the one using the old API, move to a release of it that supports AGP 9.
androidComponents {
beforeVariants(
selector().withBuildType("debug").withFlavor("color", "blue")
) { variantBuilder ->
variantBuilder.enable = false
}
}3Verify
Rebuild; the ClassCastException should not appear.
./gradlew assembleDebugConfirmed by developer.android.com
Cause 3 of 3
The kotlin-android plugin is still applied
1Check
AGP 9.0 has built-in Kotlin, enabled by default. The kotlin-android plugin is not compatible with the new DSL, so it must go (or both opt-outs must be set).
grep -rn "org.jetbrains.kotlin.android\|kotlin-android" --include=*.gradle --include=*.gradle.kts --include=*.toml .2Fix
Remove the plugin from the module files, from the top-level file and from the version catalog. Then move android.kotlinOptions to kotlin { compilerOptions { } }.
kotlin {
compilerOptions {
languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
}
}3Verify
Sync the project and build.
./gradlew assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Use the Android Gradle plugin Upgrade Assistant in Android Studio when you move to AGP 9; it keeps current behaviour where it can.
- Treat android.newDsl=false and android.builtInKotlin=false as temporary: the release notes say the opt-outs are going away.
- Check third-party Gradle plugins for AGP 9 support before you upgrade.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
applicationVariants stops working after upgrading the Android Gradle Plugin
Could not get unknown property 'applicationVariants' for BuildType_Decorated
AGP 9.0 turns on android.newDsl by default.
2 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fixMobile apps
Java and Kotlin compile to different JVM targets in an Android module
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17.
2 causes, each with a fixMobile apps
Manifest.permission.POST_NOTIFICATIONS shows red or does not resolve
Cannot resolve symbol 'POST_NOTIFICATIONS'
POST_NOTIFICATIONS exists only from API level 33.
4 causes, each with a fix