Android: auto-incrementing version number

Incrementing the version/build number for your project is important for various reasons, such as publishing an update to an app on the Google Play Store requiring a newer version. This can be easily done in your build.gradle file.

First, define a file to hold the versionCode, as shown below:

Then, you can read the version code from the file. If the file does not exist, set the code to 0. After that, increment the code and save it back to the file to be used in the next build.

Finally, set the versionCode to the code you previously computed.

The full version of your application should now be: BuildConfig.VERSION_NAME + “.” + BuildConfig.VERSION_CODE.

You can find a full implementation of this process here, and the code for the current article in in build.config.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.