Colton Idle
02/13/2026, 2:30 AMproductFlavors {
create("dev"){
`ext.envApiKey = "123".
}
create("staging"){
`ext.envApiKey = "456".
}
... repeat 3 more times since we have 5 build environments total
}
then we have another place in the build file where we iterate over each productFlavor and register a new task, and try to access that ext.envApiKey but ext doesn't exist in kts. chatGpt keeps saying that I should be able to do flavor.extra when iterating over flavors but no dice. is there some way to add like an extra property or something to a ProductFlavor so I can retrieve it elsewhere? its in the same build file if that helps.Sergej Koščejev
02/13/2026, 6:21 AM(this as ExtensionAware).extra["envApiKey"]Vampire
02/13/2026, 9:10 AMExtensionAware, so it is best to always declare it explicitly e. g. if you define an extension class or interface and similar, so that you do not need to cast it to ExtensionAware.
ProductFlavor according to https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/ProductFlavor does declare it explicitly, so a cast should not be necessary.
So you could for example do val envApiKey by theFlavor.extra.
But actually, practically any usage of ext / extra is a smell and usually a work-around for not doing something properly. But at least it should work.ephemient
02/13/2026, 9:37 AMephemient
02/13/2026, 9:39 AMephemient
02/13/2026, 9:39 AMColton Idle
02/13/2026, 2:51 PMVampire
02/13/2026, 3:03 PMThis is an interface for the gradle tooling api, and should only be used from Android Studio. It is not part of the DSL & API interfaces of the Android Gradle Plugin.so if you work with that in your build logic, you are probably anyway wrong. Or rather, you probably did not set the
ext on the product flavor, but on an outer scope, just irritating the reader by having it in the product flavor configuration. 🤷♂️Colton Idle
02/13/2026, 3:28 PM