What is the best practice to manage the version of my android app?

Inside your Manifest you should have this:

 android:versionCode="1"
 android:versionName="1.0" 

Referring to @GregoryK answer, there is am important thing that need to be mentioned.

The difference of 0 zero between each section allows max value of 9 for the minor & patch values.

(build is limited to 99 which is fine if not used in a CI/CD environment)

The values 3.0.10.0 and 3.1.0.0 will result to the same versionCode when clearly the 2nd is "bigger". The biggest problem here, is that GooglePlay will refuse to accept the 3.1.0.0 if 3.0.10.0 was uploaded because the version code already exist.

In order to solve the above we need to follow the two zeros (00) space like the build and the patch (patch can be increased until 99):

versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild

I recommend this article: https://medium.com/@maxirosson/versioning-android-apps-d6ec171cfd82

I end up adopting his build.gradle to something that fits our needs. I added a build code at the end like in the example I gave that is based on @GregoryK answer.


in your project, Gradle file versionCode will be an integer value and versionName could be any kind of text that you can recognize.

defaultConfig {
    applicationId "your id"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 2
    versionName "1.0.1"
    multiDexEnabled true

}

As to best practices, you can use a very nice approach to manage version code and name described here https://plus.google.com/+JakeWharton/posts/6f5TcVPRZij by Jake Wharton.

Basically, you can update your build.gradle to generate versionCode and versionName based on your major, minor and patch version numbers. (Code copied from the link for convenience.)

def versionMajor = 3
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

android {
  defaultConfig {
    ...
    versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
    versionName "${versionMajor}.${versionMinor}.${versionPatch}"
    ...
  }
  ...
}

Tags:

Android