Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set FlavorDimensions in AGP 7.0.0?

Since Android Studio Arctic Fox has reached stable recently, our team has decided to make the switch. However, we hit some roadblocks while upgrading our project to use the latest AGP, from 4.2.1 to 7.0.0

Below is our old app/build.gradle.kts:

android {
    
    flavorDimensions("environment")

    productFlavors {
    
        create("development") {
            dimension("environment")
            ...
        }
        
        create("staging") {
            dimension("environment")
            ...
        }
        
        create("production") {
            dimension("environment")
            ...
        }
    }
    
}

We managed to replace dimension("environment") with dimension = "environment", but we are not able to use the same approach for flavorDimensions.

flavorDimensions = listOf("environment") // syntax error because it's immutable

Any help would be gladly appreciated.

Spec for flavorDimensions showing it as val, hence not assignable

enter image description here

like image 271
You Qi Avatar asked Dec 20 '25 10:12

You Qi


1 Answers

Since it's a MutableList, we can just add it directly

flavorDimensions.add("environment")

Updates:

Alternatively, a more favourable writing style in Kotlin:

flavorDimensions += "environment"
like image 170
You Qi Avatar answered Dec 23 '25 01:12

You Qi