Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

AGP 9 marks the android block as deprecated or fails on BaseExtension

Errordeprecation warnings on the android block after upgrading to AGP 9.0

Short 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.

  • Applies to Android Gradle plugin 9.0 and later, Gradle 9.1, Kotlin 2.2.10 or newer
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.properties
  2. 2Match what you see, then jump to its fix

    1. 1gradle.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. 2ClassCastException with BaseExtension, or a script reading applicationVariants, libraryVariants or variantFilterBuild logic still uses applicationVariants or other removed variant APIFix
    3. 3Failed to apply plugin 'org.jetbrains.kotlin.android'. ... no longer required for Kotlin support since AGP 9.0The kotlin-android plugin is still appliedFix

What does the error look like?

  • deprecation warnings on the android block after upgrading to AGP 9.0
  • java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
  • Failed 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.properties

2Fix

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 line

3Verify

Run a build and read the output for remaining warnings.

./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

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 assembleDebug

Confirmed by developer.android.com

Did this fix it?

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 assembleDebug

Confirmed by developer.android.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.