赞
踩
1.添加友盟统计依赖库
- dependencies {
- compile 'com.umeng.sdk:common:latest.integration'
- compile 'com.umeng.sdk:analytics:latest.integration'
- }
如果无法正常集成请添加如下配置:
- allprojects {
- repositories {
- mavenCentral()
- }
- }
2.Manifest中配置权限和Key:
也就是清单文件中
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- <application......>
- //这里的value="5a446bf5f29d987bd200008a"是在友盟里面自己账号生成的,看图
- <meta-data android:value="5a446bf5f29d987bd200008a" android:name="UMENG_APPKEY"/>
- <meta-data android:value="${UMENG_CHANNEL_VAULE}" android:name="UMENG_CHANNEL"/>
-
- </application>
-
-
3.app build.gradle动态配置Manifest的占位符和默认值
也就是在项目的build.gradle(Module:app)中配置:
- defaultConfig {
-
- multiDexEnabled true // 突破方法数65535限制
- manifestPlaceholders = [UMENG_CHANNEL_VAULE: "umeng"]
-
-
- }
4.配置签名文件信息,注意:signingConfigs要在buildTypes之前
- signingConfigs {
- release {
- keyAlias 'key0'
- keyPassword '123456'
- storeFile file('release.jks')
- storePassword '123456'
- }
- }
- productFlavors {
- yingyongbao{
-
- }
- xiaomi{
-
- }
- }
为了简单可以用脚本去替换重复代码
-
- productFlavors.all {flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VAULE: name]
- }
6.可以配置多渠道打包输出的名字,比如打包的名字就是渠道名字
- 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);
- }
- }
- }
- }
- }
7.其他技巧:
①可以给不同渠道的apk赋不同的应用名
- productFlavors { xiaomi{
- // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
- resValue "string", "app_name", "xiaomi"
- }
- wandoujia{
- // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
- resValue "string", "app_name", "wandoujia"
- }
②给测试打不同功能点可以安装在同一个手机上的测试包
- productFlavors {
-
- okhttp {
- applicationIdSuffix "okhttp"
- resValue "string", "app_name", "okhttp"
- }
- jpush {
- applicationIdSuffix "jpush"
- resValue "string", "app_name", "jpush"
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。