Created
July 18, 2016 03:30
-
-
Save bitristan/2e6fb294d2a3ee8aae39b5c06a4e97fa to your computer and use it in GitHub Desktop.
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
apply plugin: 'android' | |
def getVersionCode = { -> | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master' | |
standardOutput = stdout | |
} | |
return Integer.parseInt(stdout.toString().trim()) | |
} | |
catch (ignored) { | |
return -1; | |
} | |
} | |
def getVersionName = { -> | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags', '--dirty' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} | |
catch (ignored) { | |
return null; | |
} | |
} | |
android { | |
defaultConfig { | |
versionCode getVersionCode() | |
versionName getVersionName() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment