Maaz Zindani

Loading the index…

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

Android build fails because a product flavor has no flavor dimension

ErrorError: 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".

  • Applies to Android Gradle plugin 8.x, Gradle 8.x, Kotlin DSL and Groovy DSL
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

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

    1. 1The 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. 2A 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

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 assemble

Confirmed by developer.android.com

Did this fix it?

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

2Fix

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 help

Confirmed by developer.android.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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