Android Studio 3.0 Flavor Dimension Issue
Asked Answered
K

8

241

Upgraded to Studio Canary build. My previous project of Telegram Messenger is giving following error.

Error:All flavors must now belong to a named flavor dimension. The flavor 'armv7' is not assigned to a flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

What should I do? I have already seen that link but couldn't understand what to do. I have 3 build variants now, release,debug and foss.

Kokaras answered 22/5, 2017 at 5:19 Comment(1)
Does this answer your question? Multi flavor app based on multi flavor library in Android GradlePanta
C
571

If you don't really need the mechanism, just specify a random flavor dimension in your build.gradle or build.gradle.kts:

android { 
    ...
    flavorDimensions("default")
    ...
}

For more information, check the migration guide

Carter answered 22/5, 2017 at 5:25 Comment(8)
Thanks. I already had a dimension "versionCode", I used that.Kokaras
flavorDimensions "versionCode" productFlavors { debug { dimension "default" versionName "1.0" } release { dimension "default" versionName "1.0" } foss { dimension "default" versionName "1.0" } } I got this error ..ProductFlavor names cannot collide with BuildType names. Could you please anyone help me. I got this error AS 3.0 beta version Canary with Kotlin.Effeminacy
What do I do if I haven't used flavors anywhere in my build.gradle? I have 2 buildTypes, debug and release.Freehold
You still get that error while not having any flavors defined? Maybe some library you include uses flavors but no has no flavorDimension?Carter
If you only have one dimension, you do not need to specify it in each flavor. Just the first flavorDimensions "default" line above is all that's needed.Beseech
@GrahamBorland thanks for the hint, I updated the answer accordingly.Carter
maybe add, that the file is app/build.gradleVoltameter
This is not solving my issue. I am having same issue.Shack
K
63

After trying and reading carefully, I solved it myself. Solution is to add the following line in build.gradle.

flavorDimensions "versionCode"

android { 
       compileSdkVersion 24
       .....
       flavorDimensions "versionCode"
} 
Kokaras answered 22/5, 2017 at 5:30 Comment(5)
where in the gradle do you add this line? A little more context would be helpfulBruce
Inside build.gradle file, in android { ... }Kokaras
android { compileSdkVersion 24.... //add here }Kokaras
why "versionCode" and not anything else ? will it affect versionCode anyhow ?Leprosy
@Leprosy I have that in my productFlavours. You just need any unique key to identify.Kokaras
L
41

Here you can resolve this issue, you need to add flavorDimension with productFlavors's name and need to define dimension as well, see below example and for more information see here https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

flavorDimensions 'yourAppName' //here defined dimensions
productFlavors {
    production {
        dimension 'yourAppName' //you just need to add this line
        //here you no need to write applicationIdSuffix because by default it will point to your app package which is also available inside manifest.xml file.

    }

    staging {
        dimension 'yourAppName' //added here also
        applicationIdSuffix ".staging"//(.staging) will be added after your default package name.
        //or you can also use applicationId="your_package_name.staging" instead of applicationIdSuffix but remember if you are using applicationId then You have to mention full package name.
        //versionNameSuffix "-staging"

    }

    develop {
        dimension 'yourAppName' //add here too
        applicationIdSuffix ".develop"
        //versionNameSuffix "-develop"

    }
Lette answered 4/1, 2018 at 5:21 Comment(0)
U
20

If you want not to use dimensions you should use this line

android { 
compileSdkVersion 24

...
flavorDimensions "default"
...
}

but if you want ti use dimensions you should declare your dimension name first and then use this name after THIS example is from the documentations:

android {
...
buildTypes {
debug {...}
release {...}
}

  // Specifies the flavor dimensions you want to use. The order in which you
  // list each dimension determines its priority, from highest to lowest,
  // when Gradle merges variant sources and configurations. You must assign
  // each product flavor you configure to one of the flavor dimensions.
  flavorDimensions "api", "mode"

  productFlavors {
    demo {
  // Assigns this product flavor to the "mode" flavor dimension.
  dimension "mode"
  ...
}

full {
  dimension "mode"
  ...
}

// Configurations in the "api" product flavors override those in "mode"
// flavors and the defaultConfig block. Gradle determines the priority
// between flavor dimensions based on the order in which they appear next
// to the flavorDimensions property above--the first dimension has a higher
// priority than the second, and so on.
minApi24 {
  dimension "api"
  minSdkVersion 24
  // To ensure the target device receives the version of the app with
  // the highest compatible API level, assign version codes in increasing
  // value with API level. To learn more about assigning version codes to
  // support app updates and uploading to Google Play, read Multiple APK Support
  versionCode 30000 + android.defaultConfig.versionCode
  versionNameSuffix "-minApi24"
  ...
}

minApi23 {
  dimension "api"
  minSdkVersion 23
  versionCode 20000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi23"
  ...
}

minApi21 {
  dimension "api"
  minSdkVersion 21
  versionCode 10000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi21"
  ...
    }
  }
}
...
Unlucky answered 30/10, 2017 at 7:43 Comment(0)
C
11

I have used flavorDimensions for my application in build.gradle (Module: app)

flavorDimensions "tier"

productFlavors {
    production {
        flavorDimensions "tier"
        //manifestPlaceholders = [appName: APP_NAME]
        //signingConfig signingConfigs.config
    }
    staging {
        flavorDimensions "tier"
        //manifestPlaceholders = [appName: APP_NAME_STAGING]
        //applicationIdSuffix ".staging"
        //versionNameSuffix "-staging"
        //signingConfig signingConfigs.config
    }
}

Check this link for more info

// Specifies two flavor dimensions.
flavorDimensions "tier", "minApi"

productFlavors {
     free {
            // Assigns this product flavor to the "tier" flavor dimension. Specifying
            // this property is optional if you are using only one dimension.
            dimension "tier"
            ...
     }

     paid {
            dimension "tier"
            ...
     }

     minApi23 {
            dimension "minApi"
            ...
     }

     minApi18 {
            dimension "minApi"
            ...
     }
}
Cantal answered 24/11, 2017 at 7:43 Comment(0)
C
3

in KotlinDSL you can use like this :

flavorDimensions ("PlaceApp")
productFlavors {
    create("tapsi") {
        setDimension("PlaceApp")
        buildConfigField("String", "API_BASE_URL", "https://xxx/x/x/")
    }

}
Cattalo answered 3/9, 2020 at 14:7 Comment(0)
A
1

If you have simple flavors (free/pro, demo/full etc.) then add to build.gradle file:

android {
...
flavorDimensions "version"
productFlavors {
        free{
            dimension "version"
            ...
            }
        pro{
            dimension "version"
            ...
            }
}

By dimensions you can create "flavors in flavors". Read more.

Aurist answered 29/8, 2019 at 8:52 Comment(0)
L
0

This what worked for me for latest as well :

android {
...
flavorDimensions += "version"
}
Lashkar answered 23/12, 2023 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.