Updating gradle file with versionCode and versionName

What is the best practice to update versionCode when deploying an app to the beta channel in Android?
I wanted to offset the current versionCode by bitrise’s build number, but I haven’t found any custom step for retrieving such information from gradle file.

Is it a good idea to have a totally custom versionCode (currently my version codes are above 100000), so maybe using just bitrise’s build number will suffice?

Thanks in advance,

There is no need to modify Gradle files during build. You can calculate a build number inside buildscript:

android {
  defaultConfig {
    def buildNumber = System.getenv("BITRISE_BUILD_NUMBER") ?: "1"
    versionCode Integer.parseInt(buildNumber) + 100000

Another approach is to use current git commit timestamp or number of commits on the current branch. This is often sufficient if app built from given commit is always the same e.g. there is no dynamic dependencies, no content downloaded at the build time nor NDK (version of which can change over the time on bitrise).


It would be nice to have a custom step for this so we could avoid making Bitrise-specific changes to our build. For now, though, this works well. Thanks!

1 Like

Depends on your setup, the Change Android versionCode and versionName step combined with the Adjust BuildNumber step can provide something like this, if you want to have a simple / static offset & use the Bitrise Build Number for the build number.

What is the point of the + 100000?

1 Like

Because OP already uses lower version codes: