Android Studio 使用友盟进行多渠道打包

AndroidManifest.xml

1
2
3
4
5
<application>
<!--友盟-->
<meta-data android:value="Umeng App Key" android:name="UMENG_APPKEY"/>
<meta-data android:value="${UMENG_CHANNEL_VALUE}" android:name="UMENG_CHANNEL"/>
</application>

引入友盟移动统计依赖

1
2
3
api 'com.umeng.umsdk:common:2.1.0'
//移动统计
api 'com.umeng.umsdk:analytics:8.1.3'

配置多渠道

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
android {
defaultConfig {
flavorDimensions "versionCode"
}

//多渠道打包支持
productFlavors {
Default { //默认版本, 服务端为生产环境
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "default"]
}
//渠道名称不能使用Test, 否则报错: ERROR: Cannot add task 'reportSourceSetTransformTest' as a task with that name already exists.
//Umeng, test, unknown都是不可以的
//Test { //服务端为开发或测试环境
//manifestPlaceholders = [UMENG_CHANNEL_VALUE: "test"]
//}
Develop { //服务端为开发或测试环境
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "develop"]
}
Home { //投放官网
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "home"]
}
Update { //投放升级服务器
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "update"]
}
GooglePlay { //投放GooglePlay
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "googleplay"]
}
Tencent { //投放应用宝市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "tencent"]
}
Wandoujia { //投放豌豆荚市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
}
Huawei { //投放华为市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"]
}
Xiaomi { //投放小米市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
}
Vivo { //投放Vivo市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "vivo"]
}
Oppo { //投放Oppo市场
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "oppo"]
}
}

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

打包命令

使用gradlew assembleRelease打生产包;gradlew assembleDebug打测试包,通常上正式渠道只需要release包

1
2
3
4
..\gradlew.bat assembleDefaultDebug assembleDefaultRelease
..\gradlew.bat assembleDevelopDebug assembleDevelopRelease
..\gradlew.bat assembleGooglePlayDebug assembleGooglePlayRelease
..\gradlew.bat assembleHomeRelease assembleUpdateRelease assembleTencentRelease assembleWandoujiaRelease assembleHuaweiRelease assembleXiaomiRelease assembleVivoRelease assembleOppoRelease

集成友盟统计功能

基础统计集成:https://developer.umeng.com/docs/119267/detail/118588
高级功能集成:https://developer.umeng.com/docs/119267/detail/118637

1
2
3
4
5
6
7
UMConfigure.init(context, UMConfigure.DEVICE_TYPE_PHONE, "Umeng Message Secret");

// 选用AUTO页面采集模式
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);

// 支持在子进程中统计自定义事件
UMConfigure.setProcessEvent(true);

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :