The “one click build” is a golden standard that developers would love to achieve. Whether it is making debug builds, builds for QA and especially release builds, the simpler the release process the better. Some even consider it a criterion to measure the health of a codebase by. And the reasoning for this is straightforward. Less steps equate to less time and, more importantly, less chance of error. One easy way to reduce the amount of steps when making a release build in Android is to use the power of the gradle build system to autogenerate the versionCode for your build.

Achieving this is simple. Define the version information for your build and use gradle to generate suitable sting and int values for the versionName and versionCode, respectively.

Here is a simple build.gradle that captures this idea:

Save time and reduce the possibility of mistakes by removing steps (no matter how trivial) from your build process.

All the cool kids are doing it. :)