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:
version.properties
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.