Created
March 26, 2014 13:45
-
-
Save Numan1617/9783467 to your computer and use it in GitHub Desktop.
Android - Automatic Version Numbering
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 code = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', 'HEAD', '--count' | |
standardOutput = code | |
} | |
return code.toString().toInteger() | |
} | |
catch (ignored) { | |
return -1; | |
} | |
} | |
def getVersionName = { -> | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim().split(/-/)[0] | |
} | |
catch (ignored) { | |
return null; | |
} | |
} | |
android { | |
defaultConfig { | |
versionCode getVersionCode() | |
versionName getVersionName()+'.'+getVersionCode() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment