Hi,
I have Android gradle (.kts files) project.
I have 2 flavors (api
and client
).
I need to set properties from file based on both flavors.
for example:
API: dev, prod
Client: ClientX, ClientY
now I need to set while built proper env/BuildConfig file, string variables, android manifest variables.
My example, how want to do it:
enum class Clients(
val applicationId: String,
val version: Version,
val isDefault: Boolean = false
) {
ClientX(...),
ClientY(...)
}
flavorDimensions += listOf("client", "api")
productFlavors {
Clients.values().forEach { client ->
create(client.name.lowercase()) {
dimension = "client"
isDefault = client.isDefault
applicationId = client.applicationId
versionCode = client.version.versionCode
versionName = client.version.versionName
}
}
create("dev") {
dimension = "api"
isDefault = true
versionNameSuffix = " (DEV API)"
val client = // TODO: how to properly get only current "client" flavor here?
val properties = loadProps(rootProject.file("secrets/${"$client/"}flavor.api.staging.properties"))
setRuntimeVariables(properties)
}
create("prod") {
dimension = "api"
val client = // TODO: how to properly get only current "client" flavor here?
val properties = loadProps(rootProject.file("secrets/${"$client/"}flavor.api.production.properties"))
setRuntimeVariables(properties)
}
}
But I have no idea / no luck (searched by gogole, stack overflow - no useful/working solution) how solve this.
Because it set variables instantly while call this code, it’s not possible to iterate over all flavors and call it for all variants, but I need only for a current variant that is built.
Some tips are in android - How to get current flavor in gradle - Stack Overflow but no one working properly.
For example and almost best variant is: android - How to get current flavor in gradle - Stack Overflow but that didn’t work when you use short build names like: ./gradlew assCXP (alias for assembleClientXProd)