I used to add some attributes to BuildConfig on my Android project depending on the build variant and other logic.
Using Gradle 7 with AGP 7.0.1 I cannot figure out how to add a BuildConfig field in the onVariants closure in my groovy gradle file:
androidComponents {
onVariants(selector().withBuildType("release"), {
...here...
})
}
I tried several things like:
it.buildConfigFields.put("MY_KEY", BuildConfigField("String", "\"$someSecretValue\"", null))
or
it.addBuildConfigField("MY_KEY", "\"$someSecretValue\"", "key description")
which is only available for build files in kotlin.
How can I do this using AGP 7's Variant Api?
This is my original code I want to migrate:
android.applicationVariants
.matching { v -> ['release'].contains(v.name) }
.all { variant ->
variant.buildConfigField('String', 'MY_KEY', '"$someSecretValue"')
}
Any suggestion is appreciated!