Last active
March 1, 2017 06:14
-
-
Save pratul/dc09131331049e7c4917b8df1ff67af0 to your computer and use it in GitHub Desktop.
A gradle method to generate Android versionCode using git describe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getVersionCode = { -> | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', '--first-parent', '--count', 'origin/master' | |
standardOutput = stdout | |
} | |
return Integer.parseInt(stdout.toString().trim()) * 100 | |
} | |
catch (ignored) { | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment