applicationVariants stops working after upgrading the Android Gradle Plugin
Could not get unknown property 'applicationVariants' for BuildType_DecoratedShort 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.
Fix it fast
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 --stacktrace2Match what you see, then jump to its fix
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.properties2Fix
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:assembleDebugConfirmed by developer.android.com
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" | head2Fix
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=false3Verify
Sync and build. Expect deprecation warnings while the opt-out is on.
./gradlew :app:assembleDebugConfirmed by developer.android.com
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
Gradle says it could not get unknown property 'android' for the root project
Could not get unknown property 'android' for root project 'android' of type org.gradle.api.Project.
The android block is added by the Android Gradle Plugin, and only to a project where that plugin is applied.
2 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix