本篇主要给大家介绍利用友盟api实现Android多渠道打包,进入友盟的官网,注册账号,添加对应的应用。
1.添加友盟库的依赖
这里写图片描述

2.在manifest.xml中声明appkey,以及渠道占位符
这里写图片描述

3.builder.gradle相关脚本配置,添加默认的渠道名
Android Studio 友盟api实现apk多渠道打包_第1张图片

Android Studio 友盟api实现apk多渠道打包_第2张图片

Android Studio 友盟api实现apk多渠道打包_第3张图片

Android Studio 友盟api实现apk多渠道打包_第4张图片

4.执行命令gradlew assembleRelease打出所有渠道的Release包,相似的命令如:assembleDebug(只打Debug包)、assemblewandoujiaRelease(只打豌豆荚渠道的包)
命令执行成功生成的安装包:
Android Studio 友盟api实现apk多渠道打包_第5张图片

Android Studio 友盟api实现apk多渠道打包_第6张图片

Android Studio 友盟api实现apk多渠道打包_第7张图片

完整的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'}

更多相关文章

  1. Android Picasso 图片加载库基础使用详解
  2. android加载网络图片(逐行扫描格式png图片)的一个bug
  3. [转] Android TextView处理HTML标签、显示图片等
  4. 2014-11-8Android学习------Android 实现图片的旋转--------动画
  5. android中使用线程池和临时缓存优化网络图片加载
  6. Android Nine Patch图片及按钮背景
  7. Android图片异步加载之Android-Universal-Image-Loader
  8. Jenkins搭建Android自动打包二之设置渠道打包
  9. Android中应用程序drawable图片资源占用内存的统计

随机推荐

  1. Android(安卓)SDK 4.0.3 开发环境配置及
  2. android am命令
  3. Android 经典示例,初学者的绝好源码资料
  4. shape的使用
  5. Android进入页面默认不弹出软键盘
  6. Android Studio 指定DEBUG和RELEASE版本
  7. Android跨进程通信传输大数据
  8. android activity onSearchRequested()
  9. API Demos 2.2 研读笔记(5)——Window Feat
  10. Android动画之 Alpha与Translate结合使用