Android Studio编译一次源码versionCode自增

再强调其中两点:

1、要特别注意getVersionCode位置,不要直接放在defaultConfig里面

2、getVersionCode方法中的toInteger()和toString()方法要加上,即使没有

 

    def currentVersionCode = getVersionCode()
    defaultConfig {
        applicationId "com.melon.myapp"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode currentVersionCode
        versionName "1.0"
def getVersionCode() {
    def propsFile = file('version.properties')
    def properties = new Properties()
    properties.load(new FileInputStream(propsFile))
    def vCode = properties['V_CODE'].toInteger()
    properties['V_CODE'] = (++vCode).toString()
    properties.store(propsFile.newWriter(), null)
    return vCode
}

 

你可能感兴趣的:(Android)