Favolas
Favolas

Reputation: 7243

Change Android applicationIdSuffix for release type

My app has 4 flavors and each one sets its own applicatioIdSuffix. I also have 4 build types.

     flavorA {
        ...
        applicationIdSuffix '.flavorA'
    }
     flavorB {
        ...
        applicationIdSuffix '.flavorB'
    }
    flavorC {
        ...
        applicationIdSuffix '.flavorC'
    }
    flavorD {
        ...
        applicationIdSuffix '.flavorD'
    }

buildTypes {
    debug {
       .....
    }

    release {
       .....
    }

    debugClient {
       .....
    }

    releaseClient {
       .....
    }
}

Now, when I'm building the releaseClient version I want to override the applicationIdSuffix setting so that no suffix is added. I've tried to do:

releaseClient {
       applicationIdSuffix ''
}

Hopping that it would override the suffix set with the flavor but this does not work.

How can I change, for a specific build type, the applicationIdSuffix set by the flavor?

Upvotes: 0

Views: 888

Answers (1)

Rémy
Rémy

Reputation: 422

Instead of add applicationIdSuffix on flavors you can do this on buildTypes {}

buildTypes {
        debug {
            ...
        }
        release {
            applicationVariants.all { variant ->
                variant.outputs.all {
                    def flavor = variant.productFlavors[0].name
                    
                    applicationIdSuffix getFlavor(flavor)
                }
            }
        }
    }




def getFlavor(String flavor) {
   val suffix = ""

    if (flavor == "A")
       suffix = ".flavorA"
    ...

    return suffix
}

Upvotes: 2

Related Questions