androidgradleandroid-gradle-plugin

Set applicationIdSuffix for specific flavor-buildType combination in Gradle 4.1


I have different build types and different flavor dimensions in my app. I want to add a specific flavor suffix to an application ID only for one specific build type.

E.g. for stageApi flavor and beta build type combination I'd like to add suffixes .stageapi and .beta so the result application ID will be my.application.stageapi.beta, but for debug and release I don't want to do that (I'd like to have my.application.debug and my.application without api suffix).

I've had this code before and it worked just fine:

    productFlavors {

        ... 

        beta {
            applicationIdSuffix ".beta"
        }
    }

    applicationVariants.all { variant ->
        def name = variant.getName()
        if (name.contains("StageApiBeta")) {
            def mergedFlavor = variant.mergedFlavor
            mergedFlavor.setApplicationIdSuffix(".stageapi")
        }
    }

But after upgrading to Gradle plugin 4.1 it stopped working. It doesn't throw any error, but the resulting application ID is my.application.beta, without .stageapi.

I tried different approaches but I just can't figure out how to do it now. I seems also that 4.2 will have other API changes as well, but I'd like to make it work in 4.1 also.


Solution

  • With Gradle Plugin 8.5.1 I managed to combine flavor- and buildType-related version name suffixes by simply adding versionNameSuffix="<suffix>" to a buildType clause like in the following example (I'm using Kotlin as the Gradle scripting language):

        buildTypes {
            getByName("release") {
                ...
            }
            getByName("debug") {
                ...
                versionNameSuffix = "-DEBUG"
            }
        }
    
        ...
    
        productFlavors {
            create("staging") {
                ...
                versionNameSuffix = "-STG"
            }
    

    For stagingDebug build variant I'm getting the -STG-DEBUG suffix.