Android Studio 多渠道打包

使用友盟统计为例

一、原来的AndroidMenifest配置中的

<meta-data 
      android:name="UMENG_CHANNEL" 
      android:value="Channel_ID" />

替换为

<meta-data 
      android:name="UMENG_CHANNEL" 
      android:value="${UMENG_CHANNEL_VALUE}" />

二、module中的build.gradle中添加如下配置

productFlavors {
        xiaomi {}
        _360 {}
        baidu {}
        wandoujia {}
        tencent{}
    }

    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }

三、Build -- Generate Signed APK... -- 选择所有Flavors -- Finish

四、完成

最后想要输出APK包时名字更容易识别的话,可以加上

buildTypes {
        debug {
            signingConfig signingConfigs.release
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        // 输出apk名称为HePingMao_v1.0.0_2015-01-15_wandoujia.apk
                        def fileName = "HePingMao_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }
        }
    }

其中releaseTime()方法需要自定义

def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
    compileSdkVersion 25
    .....
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容