Set custom applicationId depending on flavor combination with Kotlin Gradle for Android

539 Views Asked by At

With gradle scripts in groovy it's possible to customize the applicationId or applicationIdSuffix depending on combination of flavors.

applicationVariants.all { variant ->
    def name = variant.getName()
    if (name.contains("Prod") && name.contains("Paid")) {
       variant.mergedFlavor.applicationIdSuffix = ".foo"
    } else if (name.contains("Prod") && name.contains("Free")) {
       variant.mergedFlavor.applicationIdSuffix = ".bar"
    } 
    // else if ... and so on
}

I'm trying now to convert the gradle build scripts in kotlin (*.kts) and it seems like there is no way to do it, because there is no more setter methods for applicationId and applicationIdSuffix properties.

applicationVariants.all {
    mergedFlavor.applicationIdSuffix = ".foo" // error here
}

Is there any other way to do it with kotlin scripts?

I'm currently using:

gradle-5.6
com.android.tools.build:gradle:3.5.3
org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50
0

There are 0 best solutions below