I would like to use the same implementation for the android.variantFilter(...) for all my android apps modules.
Currently I have such a variantFilter in the "app"-Module which works fine:
android.variantFilter { variant ->
String buildType = variant.buildType.name
String flavor = variant.getFlavors().get(0).name
if ((buildType == 'debug' && (flavor == 'canary' || flavor == 'int' || flavor == 'prd')) ||
(buildType == 'release' && (flavor == 'dev' || flavor == 'loc')))
variant.setIgnore(true)
}
The app contains several modules however and I would like to filter the variants in all modules likewise. Without having to reimplement the same variantFilter in all module's build.gradle files.
So my question is: is there a way to define that filter in a central place (for example the app's top level builg.gradle file) and to cite it in the module specific build.gradle files?
Either put the script in a file called
variants.gradlein the parent directory and apply it:Or use
AndroidComponentsExtension.beforeVariantsand
DslLifecycle.finalizeDsl(the only option available):Which means, that variants can be programmatically configured, without declaring them explicitly. See this answer of mine... it's possibly not
variant.setIgnore(true)butvariant.enabled = false.