基于友盟SDK
1.修改AndroidManifest.xml
<meta-data android:value="${UMENG_CHANNEL_VALUE}" android:name="UMENG_CHANNEL"/>
2.修改module下build.gradle
A.添加打包渠道
android{
productFlavors {
xiaomi {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
}
qh360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "qh360"]
}
wandoujia {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
}
huawei {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"]
}
}
}
B.添加flavorDimensions "versionCode"
defaultConfig {
applicationId "com.musejianglan.gank"
minSdkVersion 14
targetSdkVersion 26
versionCode 3
versionName "3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
flavorDimensions "default"
}
在defaultConfig中添加flavorDimensions "default"即可,这是是studio3.0引入的新规则
原则上,多渠道基本配置完成。首先builde一下,然后开在AndroidStudio菜单栏点击Build菜单–>Generate signed APK开始打包
如果需要自定义apk的名字
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// 自定义输出配置
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "gank_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
}
}
}
}
注意
如果项目中有多个module进行依赖,保证buildTypes { }子项数量及名称一致
例如
app:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// 自定义输出配置
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
outputFileName = "gank_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
// output.outputFile = new File(outputFile.parent, outputFileName)
}
}
}
}
}
library:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
如果app有debug项,子项也要添加同名子项。内容为空即可
支付宝发红包啦!即日起还有机会额外获得余额宝消费红包!长按复制此消息,打开最新版支付宝就能领取!q1iF0j95U0