This article is a part of series: Configuring Android Project Little Things That Matter Version Name & Code Static Code Analysis Tools Continuous Integration Everything we have discussed in current article is available in project. template Version Name & Code Developers usually use some hard coded values for android & versionName versionCode. <a href="https://medium.com/media/f04f0b271a860d651b4eec03c1a3855a/href">https://medium.com/media/f04f0b271a860d651b4eec03c1a3855a/href</a> Such approach has several disadvantages: You never know which commit represent a specific version. Whenever you increment and change you have to modify file. versionCode versionName build.gradle If you are using as your source control system it can also help you to generate android & . It’s a common practice to use to indicate release of new version. git versionName versionCode git tags Version Name For we can use command. versionName git describe a. The command finds the most recent tag that is reachable from a commit. b. If the tag points to the commit, then only the tag is shown. c. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit. Example (a-b) Mark a specific commit with tag 1.0 Checkout this commit Call git describe -tags Output: 1.0 As you can see if you call on a commit with some tag, it will output this tag. git describe HEAD Example (a-c) Mark a commit with tag 1.0 Add two more commits Call git describe -tags Output: 1.0-2-gdca226a Using we can easily find out from which specific commit build was made. git commit hash “1.0–2-g dca226a ” Version Code For we can use total number of tags. Because every git tag indicate some version, for next version will be always greater then previous. versionCode versionCode In the example above we have 3 tags. This value will be used for our versionCode. However we are not going to create a git tag for every version, so for we can use a timestamp of commit. intermediate dev build HEAD In the example above a timestamp of commit is equal to This value will be used for our If you want to convert it to a human readable date use site. In our case it’s . HEAD 1484407970 (seconds since the UNIX epoch January 1, 1970 00:00:00 UTC). versionCode. currentmillis.com Sat Jan 14 2017 15:32:50 UTC way to use Groovy git To work with I suggest to use a library called . Create file with following content: git grgit script-git-version.gradle <a href="https://medium.com/media/899d5870580a1b4c8581154ad1a70e99/href">https://medium.com/media/899d5870580a1b4c8581154ad1a70e99/href</a> Apply it to your file: build.gradle <a href="https://medium.com/media/574b6c7dae7d34a4b136e2c15a92cd16/href">https://medium.com/media/574b6c7dae7d34a4b136e2c15a92cd16/href</a> To check if version name and code are generated correctly call gradle task which gives you similar output: ./gradlew printVersion <a href="https://medium.com/media/785a01221074e6ed620d343485aa5c8e/href">https://medium.com/media/785a01221074e6ed620d343485aa5c8e/href</a> Finally use , and variables in your file. gitVersionName gitVersionCode gitVersionCodeTime build.gradle <a href="https://medium.com/media/85b229e6fdca9075135c82047b59def9/href">https://medium.com/media/85b229e6fdca9075135c82047b59def9/href</a> Run project and verify app version. Benefits of such approach: No need to modify file - and are generated automatically. build.gradle versionCode versionName You can easily find out from which commit build was made. you can experiment with version name even more: include branch name, timestamp, etc. Note: