Android 自动递增版本号

来源:互联网 发布:开个网络超市 编辑:程序博客网 时间:2024/06/06 00:31
def gitVersionCode() {      def cmd = 'git rev-list HEAD --first-parent --count'    cmd.execute().text.trim().toInteger()}def gitVersionTag() {      def cmd = 'git describe --tags'    def version = cmd.execute().text.trim()    def pattern = "-(\\d+)-g"    def matcher = version =~ pattern    if (matcher) {        version = version.substring(0, matcher.start()) + "." + matcher[0][1]    } else {        version = version + ".0"    }    return version}android {      compileSdkVersion 23    buildToolsVersion "23.0.2"    defaultConfig {        applicationId "com.race604.example"        minSdkVersion 15        targetSdkVersion 23        versionCode 1        versionName '1.0'    }    buildTypes {        debug {            // 为了不和 release 版本冲突            applicationIdSuffix ".debug"        }        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    applicationVariants.all { variant ->        if (variant.buildType.name.equals('release')) {            variant.mergedFlavor.versionCode = gitVersionCode()            variant.mergedFlavor.versionName = gitVersionTag()        }    }}
原创粉丝点击