Created
April 20, 2017 05:26
-
-
Save goodev/8d274519b22f93e16f1d83b57d999498 to your computer and use it in GitHub Desktop.
git version name and code
This file contains 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: '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