1

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
yital9
  • 6,544
  • 15
  • 41
  • 54
  • Try with method `getByName()`. Don't know if I'll work but can be lucky shot. I.e. `(mergedFlavor.getByName("applicationIdSuffix") as String?) = ".foo"` – Jeel Vankhede Dec 12 '19 at 12:57
  • Unfortunately `mergedFlavor` has no `getByName` method (also tried with `productFlavors`) – yital9 Dec 12 '19 at 13:07
  • That means you'll have to wait and revert to groovy unless kotlin have `AppExtensions` compatibility, check source from here https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.AppExtension.html. – Jeel Vankhede Dec 12 '19 at 13:32

0 Answers0