Android build fails because a product flavor has no flavor dimension
Error: All flavors must now belong to a named flavor dimension.Short answer
Android Gradle plugin refuses to build when a product flavor is not assigned to a flavor dimension. Declare the dimension with flavorDimensions, then set dimension on every flavor. With only one dimension the plugin assigns flavors for you, so the error means a dimension is missing or a second one exists. In Kotlin DSL, use the property form flavorDimensions += "name".
Fix it fast
1Find out which cause you have
List the product flavors and the dimensions in the module build file. Every flavor name must be matched by a dimension line, and the dimension must be declared above it.
grep -n -E 'flavorDimensions|productFlavors|dimension' app/build.gradle*2Match what you see, then jump to its fix
- 1
The error names one specific flavor: The flavor 'x' is not assigned to a flavor dimensionNo dimension is declared, or one flavor was left out when you have severalFix - 2
A deprecation warning on flavorDimensions in build.gradle.kts, or an older tutorial's call styleThe old function call flavorDimensions("x") in a Kotlin DSL build fileFix
- 1
What does the error look like?
Error: All flavors must now belong to a named flavor dimension.The flavor 'flavor_name' is not assigned to a flavor dimension.
Cause 1 of 2
No dimension is declared, or one flavor was left out when you have several
1Check
The plugin only assigns flavors automatically when the module has exactly one dimension. If you list two dimensions, or none, each flavor needs its own dimension line.
grep -n -E 'flavorDimensions|dimension' app/build.gradle*2Fix
Declare the dimensions, then give each flavor the dimension it belongs to. Flavors in the same dimension are never combined with each other.
android {
flavorDimensions += listOf("api", "mode")
productFlavors {
create("demo") { dimension = "mode" }
create("full") { dimension = "mode" }
create("minApi28") { dimension = "api" }
}
}3Verify
List the variants Gradle now creates. Each one combines one flavor per dimension with a build type.
./gradlew :app:tasks --all | grep assembleConfirmed by developer.android.com
Cause 2 of 2
The old function call flavorDimensions("x") in a Kotlin DSL build file
1Check
In the Android DSL reference, the flavorDimensions function with a vararg argument is deprecated and replaced by the flavorDimensions property.
grep -n 'flavorDimensions' app/build.gradle.kts2Fix
Write it as the property and add to it, as the build-variants guide does.
android {
flavorDimensions += "version"
productFlavors {
create("demo") { dimension = "version" }
}
}3Verify
Sync again. The deprecation warning on that line is gone.
./gradlew helpConfirmed by developer.android.com
How do I stop it coming back?
- Declare flavorDimensions before productFlavors, and set dimension on every flavor even when you have only one dimension.
- Name dimensions deliberately; library modules match variants by dimension name.
- Copy build-file syntax from the current Android developer guide, not an old tutorial.
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
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
Android build fails because two libraries ship the same META-INF file
More than one file was found with OS independent path
Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins.
3 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
kaptDebugKotlin fails with a KaptExecution error in Room or Hilt projects
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
KaptExecution is only the wrapper: the real error comes from an annotation processor such as Room or Dagger.
3 causes, each with a fix