Android app内显示git分支名称

有时候出于开发目的需要在app内显示当前分支名称
google了一下,这里记录一下

来源https://stackoverflow.com/questions/7911844/how-to-show-current-git-branch-in-an-android-application-programatically

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
}

你可能感兴趣的:(Android app内显示git分支名称)