Automatic versioning of Android build using git describe with Gradle

Put the following in your build.gradle file for the project. There’s no need to modify the manifest directly: Google provided the necessary hooks into their configuration. def getVersionCode = { -> try { def code = new ByteArrayOutputStream() exec { commandLine ‘git’, ‘tag’, ‘–list’ standardOutput = code } return code.toString().split(“\n”).size() } catch (ignored) { return …

Read more