android 多渠道打包

2018-07-02  本文已影响13人  陨石坠灭

gradle 版本:4.1 (gradle-4.1-all.zip)

在defaultConfig添加:

defaultConfig{
...
  flavorDimensions "versionCode"
...
}

buildTypes中的配置:

buildTypes {
        release {
            signingConfig signingConfigs.release //设置签名信息
            minifyEnabled true //混淆开启
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
            manifestPlaceholders = [
                APK_CHANEL:"Baidu Market"
            ]

            applicationVariants.all { variant ->
                if (variant.buildType.name == 'release') {
                    variant.outputs.all { output ->
                        def outputFile = output.outputFile
                        if (outputFile != null && outputFile.name.endsWith('.apk')) {
                            def fileName = "release_v${defaultConfig.versionName}_${releaseTime()}_${variant.flavorName}.apk"
                            output.outputFileName = fileName
                        }
                    }
                }
            }

        }
        debug {
            signingConfig signingConfigs.release
            manifestPlaceholders = [
                APK_CHANEL:"Baidu Market"
            ]
        }

    }

在buildTypes下面添加:

productFlavors{
        baidu {
            manifestPlaceholders = [
                    APK_CHANEL:"Baidu Market"
            ]
        }
...
}

在最外层添加:

def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

上一篇下一篇

猜你喜欢

热点阅读