Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android product flavors versionNameSuffix

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

like image 812
mars3142 Avatar asked Sep 18 '14 08:09

mars3142


People also ask

What is a build type and a product flavor in android?

buildType is the how of the build. flavor is the what of the build.

What is Gradle flavor?

To do this, the Android plugin for Gradle allows you to create multiple groups of product flavors as flavor dimensions. When building your app, Gradle combines a product flavor configuration from each flavor dimension you define, along with a build type configuration, to create the final build variant.


1 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.

like image 54
Thymine Avatar answered Sep 23 '22 03:09

Thymine