Skip to content

Instantly share code, notes, and snippets.

@bitristan
Created July 18, 2016 03:30
Show Gist options
  • Save bitristan/2e6fb294d2a3ee8aae39b5c06a4e97fa to your computer and use it in GitHub Desktop.
Save bitristan/2e6fb294d2a3ee8aae39b5c06a4e97fa to your computer and use it in GitHub Desktop.
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