Created
June 13, 2018 14:30
-
-
Save augustomen/a8bb0a89fefdd166ccf89a082a20a5d4 to your computer and use it in GitHub Desktop.
Obtain Android versionCode from git commit count
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 loadVersionCode() { | |
def code = 1 | |
new ByteArrayOutputStream().withStream { os -> | |
exec { | |
commandLine 'git', 'rev-list', 'HEAD', '--count' | |
standardOutput = os | |
} | |
code = os.toString().toInteger() | |
} | |
println "Version Code: $code" | |
return code | |
} | |
android { | |
defaultConfig { | |
... | |
versionCode loadVersionCode() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment