本篇主要给大家介绍利用友盟api实现Android多渠道打包,进入友盟的官网,注册账号,添加对应的应用。
1.添加友盟库的依赖
2.在manifest.xml中声明appkey,以及渠道占位符
3.builder.gradle相关脚本配置,添加默认的渠道名
4.执行命令gradlew assembleRelease打出所有渠道的Release包,相似的命令如:assembleDebug(只打Debug包)、assemblewandoujiaRelease(只打豌豆荚渠道的包)
命令执行成功生成的安装包:
完整的builder.gradle配置代码如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.czhappy.autoinstall"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true //突破应用方法数65535的一个限制
manifestPlaceholders=[UMENG_CHANNEL_VALUE:"umeng"]
}
/*
添加签名文件
*/
signingConfigs{
Debug{}
//为我们的release添加签名配置
release{
storeFile file("cztest.jks")
storePassword "happy123456"
keyAlias "happy"
keyPassword "happy123456"
}
}
buildTypes {
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")){
def fileName = "${variant.productFlavors[0].name}" + ".apk"
output.outputFile = new File(outputFile.parent, fileName);
}
}
}
}
}
/*
渠道号名称
*/
productFlavors{
xiaomi{
//manifestPlaceholders=[UMENG_CHANNEL_VALUE:"xiaomi"]
//resValue "string", "app_name", "xiaomi_app"
}
wandoujia{
//manifestPlaceholders=[UMENG_CHANNEL_VALUE:"wandoujia"]
//resValue "string", "app_name", "wandoujia_app"
}
// okhttp{
// applicationIdSuffix "okhttp"
// resValue "string", "app_name", "okhttp"
// }
//
// jpush{
// applicationIdSuffix "jpush"
// resValue "string", "app_name", "jpush"
// }
}
productFlavors.all{
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.lzy.net:okgo:2.1.4'
compile 'com.daimajia.numberprogressbar:library:1.2@aar'
compile 'com.umeng.analytics:analytics:latest.integration'
}