Define buildconfigfield for an specific flavor AND buildType
Loop the variants and check their names:
productFlavors { vanilla {} chocolate {}}applicationVariants.all { variant -> println("Iterating variant: " + variant.getName()) if (variant.getName() == "chocolateDebug") { variant.buildConfigField "boolean", "VARIABLE", "true" } else { variant.buildConfigField "boolean", "VARIABLE", "false" }}
Here is a solution without lacks I've described under Simas answer
buildTypes { debug {} release {}}productFlavors { vanilla { ext { variable = [debug: "vanilla-debug value", release: "vanilla-release value"] } } chocolate { ext { variable = [debug: "chocolate-debug value", release: "chocolate-release value"] } }}applicationVariants.all { variant -> def flavor = variant.productFlavors[0] variant.buildConfigField "boolean", "VARIABLE", "\"${flavor.variable[variant.buildType.name]}\""}
Within the Gradle build system, buildTypes
and productFlavors
are unfortunately two separate entities.
As far as I am aware, to complete what you want to achieve, you would need to create another build flavour as such:
buildTypes { debug{} release {} } productFlavors { vanillaDebug { buildConfigField BOOLEAN, VARIABLE, FALSE } vanillaRelease { buildConfigField BOOLEAN, VARIABLE, TRUE } chocolate { buildConfigField BOOLEAN, VARIABLE, FALSE } }