Skip to content

Instantly share code, notes, and snippets.

@goodev
Created April 20, 2017 05:26
Show Gist options
  • Save goodev/8d274519b22f93e16f1d83b57d999498 to your computer and use it in GitHub Desktop.
Save goodev/8d274519b22f93e16f1d83b57d999498 to your computer and use it in GitHub Desktop.
git version name and code
apply plugin: 'com.android.application'
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null;
}
}
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;
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "org.goodev."
minSdkVersion 17
targetSdkVersion 25
versionCode getVersionCode()
versionName getVersionName()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment