有时候出于开发目的需要在app内显示当前分支名称
google了一下,这里记录一下
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1"
resValue "string", "gitBranch", gitBranch()
}
buildTypes {...}
}
def gitBranch() {
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}