Gradle script to autoversion and include the commit hash in Android

前端 未结 5 1928
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 17:31

I need to write a gradle script to auto version my application on every commit. I need to also include the commit hash as a reference in the application for testers.

5条回答
  •  庸人自扰
    2020-12-07 18:14

    add following code to your build.gradle

    def gitCommitHash = 'git rev-parse --verify --short HEAD'.execute().text.trim()
    
    defaultConfig{
        ... otherConfigs
        buildConfigField("String", "GIT_HASH", "\"${gitCommitHash}\"")
    }
    
    

    now you can get git hash by BuildConfig.GIT_HASH

    have fun

提交回复
热议问题