Android: auto-incrementing version number

For various reasons (for example publishing an update to an app on Google Play Store will require it to have a newer versions), you should increment the version/build number for your project.

This can be easily done in your build.gradle file.

First you define a file to hold the versionCode (version.properties below). You read the code from it (if the file does not exist, set the code to 0), then you increment it, and save it back to the file to be used on the next build.

Finally set the versionCode to the code you previously computed.

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

A full implementation can be found 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.