Automatic versioning of Android build using git describe with Gradle

后端 未结 10 1995
醉酒成梦
醉酒成梦 2020-11-30 18:18

I have searched extensively, but likely due to the newness of Android Studio and Gradle. I haven\'t found any description of how to do this. I want to do basically exactly

10条回答
  •  星月不相逢
    2020-11-30 19:21

    Define simple function in gradle file:

    def getVersion(){
        def out = new ByteArrayOutputStream();
        exec {
            executable = 'git'
            args = ['describe', '--tags']
            standardOutput = out
        }
        return out.toString().replace('\n','')
    }
    

    Use it:

    project.version = getVersion()
    

提交回复
热议问题