Search code examples
androidandroid-gradle-pluginandroid-build-type

Application Id based on build type


I need to change full application Id based on build type not adding a suffix after Id. I have tried to move applicationId inside each build type but Gradle uses the last one in the last build type by default. Is that possible?


Solution

  • You can use gradle filter to ignore some build/flavor targets.
    Check the following code:

    variantFilter { variant ->
       def flavor = variant.flavors*.name
       def buildType = variant.buildType*.name
    
       // To check for a certain build type, use variant.buildType.name == "<buildType>"
       if ((flavor.contains("xyz") && buildType.contains("debug"))) {
           // Gradle ignores any variants that satisfy the conditions above.
           setIgnore(true)
       }
    }