Autoincrement VersionCode with gradle extra properties

前端 未结 16 2256
逝去的感伤
逝去的感伤 2020-11-27 08:47

I\'m building an Android app with gradle. Until now I used the Manifest file to increase the versionCode, but I would like to read the versionCode from an external file and

16条回答
  •  甜味超标
    2020-11-27 09:30

    Another option, for incrementing the versionCode and the versionName, is using a timestamp.

    defaultConfig {
       versionName "${getVersionNameTimestamp()}"
       versionCode getVersionCodeTimestamp()
    }
    
    
    def getVersionNameTimestamp() {
        return new Date().format('yy.MM.ddHHmm')
    }
    
    def getVersionCodeTimestamp() {
        def date = new Date()
        def formattedDate = date.format('yyMMddHHmm')
        def code = formattedDate.toInteger()
        println sprintf("VersionCode: %d", code)
        return code
    }
    

    Starting on January,1 2022 formattedDate = date.format('yyMMddHHmm') exceeds the capacity of Integers

提交回复
热议问题