Home » Android » Android product flavors versionNameSuffix

Android product flavors versionNameSuffix

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m using buildTypes and productFlavors. My app also uses an analytics tool and this tool used the versionName of my app.

How can I change the versionName per flavor? My test was

productFlavors {
    google {
        versionNameSuffix ".google"
    }
}

but it failed. Does anybody has an idea how to custom the versionName depending on the flavor?

Update

Apparently the 2.2.0 version of Gradle Android plugin now allows setting versionNameSuffix in productFlavors

How to&Answers:

This is still a work in progress for me, but seems to work:

productFlavors {
    development {
        versionName = android.defaultConfig.versionName + (System.getenv("BUILD_NUMBER") as Integer ? "-build" + System.getenv("BUILD_NUMBER") as Integer : "-developerBuild")
    }
}

So we can set the versionName in defaultConfig, on the build server it sets the environmental variable BUILD_NUMBER, so ends up being like: 1.2-build1234 The production build only uses the defaultConfig so is just 1.2, and when building on dev machines the environmental variable isn’t set so its 1.2-developerBuild

Just came up with this plan tonight (so could be simplified i’m sure), so working on getting the latest source control revision added when on a dev machine, but i’ve seen other answers with how to do that.

Answer:

You can set the entire version name through a flavor, like this:

productFlavors {
    flavor_a {
        versionName 'Version_A'
    }
    flavor_b {
        versionName 'Version_B'
    }
}
defaultConfig {
    versionName 'Default_version_name'
}

If a flavor doesn’t specify a version name, it will pick it up from defaultConfig.