1、在AndroidManifest.xml里配置
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />
2、在build.gradle 设置productFlavors
android {
productFlavors {
baidu {}
xiaomi {}
_360 {}
wandoujia {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
3、然后同步后,打包方式有两种方式
3.1通过Build->Generate Signed APK来打包
3.2通过assembleRelease来打包,如下图所示
双击之后生成如下文件
两个配置范例如下:
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "read.eyydf.jokecollection.episode"
minSdkVersion 16
targetSdkVersion 22
versionCode 242
versionName "2.4.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
duanzi {
applicationId "read.eyydf.jokecollection.episode"
minSdkVersion 16
targetSdkVersion 22
versionCode 242
versionName "2.4.2"
manifestPlaceholders = [appname: "暴笑段子",applogo: "@mipmap/logo"]
}
baike {
applicationId "read.terr.jokecollection.encyclopedia"
minSdkVersion 16
targetSdkVersion 22
versionCode 237
versionName "2.3.7"
manifestPlaceholders = [appname: "暴笑百科",applogo: "@mipmap/baikeicon"]
}
ribao {
applicationId "read.eyydf.terr.jokecollection"
minSdkVersion 16
targetSdkVersion 22
versionCode 272
versionName "2.7.2"
manifestPlaceholders = [appname: "暴笑日报",applogo: "@mipmap/baoxiaoribaologo"]
}
}
}
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
signingConfigs {
release {
storeFile file('D:/FMSD/签名文件/cet.keystore')
storePassword '3158710702'
keyAlias 'cet.keystore'
keyPassword '3158710702'
}
fmsd {
storeFile file('D:/FMSD/签名文件/fmsd_cet.keystore')
storePassword '3158710702'
keyAlias 'fmsd_cet.keystore'
keyPassword '3158710702'
}
}
defaultConfig {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//启用混淆配置
minifyEnabled false
//Zip代码压缩优化
zipAlignEnabled true
//加载默认混淆文件
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
//启用混淆配置
minifyEnabled false
//Zip代码压缩优化
zipAlignEnabled true
//加载默认混淆文件
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//debugs使用release签名
signingConfig signingConfigs.release
}
zhuohong {
//启用混淆配置
minifyEnabled false
//Zip代码压缩优化
zipAlignEnabled true
//加载默认混淆文件
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
fmsd {
//启用混淆配置
minifyEnabled false
//Zip代码压缩优化
zipAlignEnabled true
//加载默认混淆文件
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.fmsd
}
}
productFlavors {
zhuohong_tencent {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语四六级",UMENG_CHANNEL_VALUE: "tencent",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
zhuohong_baidu {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语考试",UMENG_CHANNEL_VALUE: "baidu",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
zhuohong_xiaomi {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语宝典四六级",UMENG_CHANNEL_VALUE: "xiaomi",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
zhuohong_vivo {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语考试",UMENG_CHANNEL_VALUE: "vivo",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
zhuohong_qihu360 {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语考试四六级",UMENG_CHANNEL_VALUE: "qihu360",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
zhuohong_oppo {
applicationId "com.doding.cet"
minSdkVersion 14
targetSdkVersion 21
versionCode 102
versionName "1.0.2"
manifestPlaceholders = [APP_NAME: "英语考试",UMENG_CHANNEL_VALUE: "oppo",APP_ICON:"@drawable/icon"
,UMENG_APPKEY:"596c087e310c93232700028d",UMENG_MESSAGE_SECRET:"a70b69de4dd8710605d57f1f5701c9c1"
,RECEIVER_ACTION_NAME:"com.doding.cet",PROVIDER_AYTHORITIES_NAME:"com.doding.cet"]
}
}
}
signingConfigs {
release {
storeFile file('C:/Users/lw/Desktop/训狗/dogtraining.keystore')
storePassword '3158710702'
keyAlias 'dogtraining.keystore'
keyPassword '3158710702'
}
}
productFlavors {
xiaomi {
/* applicationId "pet.mengchong.home"
minSdkVersion 16
targetSdkVersion 22
versionCode 100
versionName "1.0.0"*/
manifestPlaceholders = [appname: "训狗养狗助手",UMENG_CHANNEL: "xiaomi"]
}
vivo {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "xiaomi"]
}
tencent {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "tencent"]
}
oppo {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "oppo"]
}
huawei {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "huawei"]
}
qihu360 {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "qihu360"]
}
meizu {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "meizu"]
}
ali {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "ali"]
}
baidu {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "baidu"]
}
lenovo {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "lenovo"]
}
sogou {
manifestPlaceholders = [appname: "训狗养狗助手-宠物社区",UMENG_CHANNEL: "sogou"]
}
}
小提示:Debug和Release的区别
Debug:调试版本,包含调试信息,所以容量比Release大很多,并且不进行任何优化(优化会使调试复杂化,因为源代码和生成的指令间关系会更复杂),便于程序员调试。
Release:发布版本,不对源代码进行调试,编译时对应用程序的速度进行优化,使得程序在代码大小和运行速度上都是最优的。
参考文章
两分钟教你搞定Gradle多渠道打包
gradle多渠道打包替换图片、xml等资源文件
网友评论