Search code examples
androidandroid-gradle-pluginandroid-productflavors

For muti-dimension flavors, how to disable certain combinations?


My Android project has two flavor dimensions but some variants (certain dimension combinations) do not make sense and so I would like to disable/omit them.

Furthermore, for some variants I do not want both debug and release build types (one is enough because those variants are for internal use only).

How to achieve both of these?


Solution

  • Use variantFilter like below. Here, we want to disable the variant of a certain flavor combination for debug build type:

    android {
        ...
        android.variantFilter { variant ->
            def name1 = variant.getFlavors().get(0).name
            def name2 = variant.getFlavors().get(1).name
            def isDebug = variant.buildType.name.equals('debug')
            if (name1.equals('ignoredName1') && name2.equals('ignoredName2') && isDebug)
                variant.setIgnore(true);
            }
        }
        ...
    }