I am converting an Android app to the Gradle Kotlin-DSL by using Kotlinscript files.
I have a problem converting our applicationId
logic. We don't use the defaultConfiguration
with applicationId
plus various applicationIdSuffix
for our flavors but a custom logic. The logic is described in this SO answer, here is the groovy code:
flavorDimensions "price", "dataset"
productFlavors {
free { dimension "price" }
paid { dimension "price" }
dataset1 { dimension "dataset" }
dataset2 { dimension "dataset" }
}
android.applicationVariants.all { variant ->
def mergedFlavor = variant.mergedFlavor
switch (variant.flavorName) {
case "freeDataset1":
mergedFlavor.setApplicationId("com.beansys.freeappdataset1")
break
case "freeDataset2":
mergedFlavor.setApplicationId("com.beansys.freedataset2")
break
case "paidDataset1":
mergedFlavor.setApplicationId("com.beansys.dataset1paid")
break
case "paidDataset2":
mergedFlavor.setApplicationId("com.beansys.mypaiddataset2")
break
}
}
With kotlin I cannot alter the applicationId
of the mergedFlavor
like in groovy. It is a val and therefore can't be changed.
Any elegant solution to solve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…