Set applicationIdSuffix for specific flavor-buildType combination in Gradle 4.1
Asked Answered
P

2

6

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.

Poussin answered 29/12, 2020 at 17:10 Comment(1)
I'm encountering the same issue after upgrading to 4.1.1, mergedFlavor.setApplicationId still works so if I can't find a better solution I'll just concatenate all the applicationIds and set them that way.Oireachtas
A
0

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.

Apache answered 4/10, 2024 at 8:50 Comment(0)
A
0

Use flavorDimensions and set different suffix to your variants.

flavorDimensions "dimen1" "dimen2"
productFlavors {
   beta {
     applicationIdSuffix ".beta"
     dimension "dimen1"
   }
   stageapi {
     applicationIdSuffix ".stageapi"
     dimension "dimen2"
   }
}
Anissa answered 29/12, 2020 at 17:22 Comment(1)
As I mentioned in the question, I'd like to have it only for particular combinations. With this approach it will be applied to all of them. E.g. debug-stageApi combination will result in my.application.stageapi.debug, which I don't want.Poussin
A
0

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.

Apache answered 4/10, 2024 at 8:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.