Android build.gradle 使用 Svn,Git
2017-10-31 本文已影响63人
coolfireApy
Svn
- 读取Svn Revision Number
def getSvnRevisionNumber() {
return 'svn info --show-item revision'.execute().text.trim()
}
- 读取Svn日志
def getSvnVersionInfo() {
return 'svn log -r HEAD'.execute().text.trim()
}
- 读取Svn Tag(不会)
Git
- 读取Git commit number,作为Version Code
def gitGitVersionCode() {
return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
}
- 读取Git Tag,作为Version Name
def getGitVersionName() {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return "1.0.0"
}
}
- 读取Git日志
def getGitVersionInfo() {
return 'git rev-parse --short HEAD'.execute().text.trim()
}
build.gradle中使用Git提交记录
//默认配置
defaultConfig {
applicationId "com.huyingbao.simple"
multiDexEnabled true//支持Multidex分包
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode gitGitVersionCode()
versionName getGitVersionName()
signingConfig signingConfigs.debug
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true//使用vector图片
ndk { abiFilters "armeabi-v7a" }//配置ndk
packagingOptions { exclude "lib/arm64-v8a/librealm-jni.so" }//ReactNative配置
}
源码RxFlux2,欢迎点赞指正!