Maaz Zindani

Loading the index…

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

applicationVariants stops working after upgrading the Android Gradle Plugin

ErrorCould not get unknown property 'applicationVariants' for BuildType_Decorated

Short answer

AGP 9.0 turns on android.newDsl by default. That removes the old variant API, including applicationVariants and libraryVariants, so any script or plugin that still calls them fails. Rewrite the script with androidComponents.onVariants, or set android.newDsl=false while you migrate.

  • Applies to Android Gradle Plugin 9.0, Gradle 9.1
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which AGP version you are on, and which file the error points to. A line from your own build file means cause 1; a plugin's class in the stack trace means cause 2.

    grep -rn "applicationVariants\|libraryVariants" --include=*.gradle --include=*.kts .
    ./gradlew :app:assembleDebug --stacktrace
  2. 2Match what you see, then jump to its fix

    1. 1The error points at your build.gradle(.kts) and appeared right after moving to AGP 9Your own build script still uses the old variant APIFix
    2. 2The stack trace names a plugin class, not your build fileA third-party plugin still calls the old APIFix

What does the error look like?

  • Could not get unknown property 'applicationVariants' for BuildType_Decorated

Cause 1 of 2

Your own build script still uses the old variant API

1Check

The AGP 9.0 release notes say android.newDsl changed its default from false to true, and that the legacy variant API such as android.applicationVariants is no longer accessible. Check the AGP version and the property.

grep -n "com.android" build.gradle build.gradle.kts gradle/libs.versions.toml 2>/dev/null
grep -n "newDsl" gradle.properties

2Fix

Replace applicationVariants, libraryVariants, testVariants and unitTestVariants with androidComponents.onVariants. Not every old call has a direct replacement; the release notes suggest filing an issue for a use case the new API does not cover.

// build.gradle.kts
androidComponents {
    onVariants { variant ->
        // work on each variant here, for example:
        println("variant: " + variant.name)
    }
}

3Verify

Build the app again; the property error should be gone.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

A third-party plugin still calls the old API

1Check

The release notes say that if incompatible third-party plugins block you, you can opt out and get the old DSL and variant API back. Plugins you can update should be updated first.

./gradlew :app:assembleDebug --stacktrace 2>&1 | grep -i "plugin" | head

2Fix

Update the plugin to a version that supports AGP 9. If none exists yet, opt out temporarily in gradle.properties and remove the line once your plugins are compatible.

# gradle.properties
android.newDsl=false

3Verify

Sync and build. Expect deprecation warnings while the opt-out is on.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Read the release notes before raising the AGP version, and use the AGP Upgrade Assistant for the first pass.
  • Search the project for applicationVariants and libraryVariants before every major AGP upgrade.
  • Treat android.newDsl=false as a short loan, and write down which plugin forced it.

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

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

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