今天以umeng为例讲解gradle的多渠道打包

1,在manifest里面配置如下信息

<meta-data android:name="UMENG_CHANNEL"    android:value="${UMENG_CHANNEL_VALUE}"/>
2,在build.gradle里进行如下配置

def releaseTime() {    return new Date().format("yyyy-MM-dd")}android {    compileSdkVersion 23    buildToolsVersion "23.0.1"    defaultConfig {        applicationId "com.guojinbao.app"        minSdkVersion 9        targetSdkVersion 23        versionCode 5        versionName "1.5.0"        // dex突破65535的限制//        multiDexEnabled true        // 默认是umeng的渠道        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "hwyy"]    }    lintOptions {        checkReleaseBuilds false        abortOnError false    }    packagingOptions {        exclude 'META-INF/DEPENDENCIES'        exclude 'META-INF/LICENSE'        exclude 'META-INF/LICENSE.txt'        exclude 'META-INF/license.txt'        exclude 'META-INF/NOTICE'        exclude 'META-INF/NOTICE.txt'        exclude 'META-INF/notice.txt'        exclude 'META-INF/ASL2.0'    }    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_6  targetCompatibility JavaVersion.VERSION_1_6  }    signingConfigs {        release {            storeFile file("../guojinbao_release.jks")            storePassword "VmVTQi6n"            keyAlias "guojinbao"            keyPassword "VmVTQi6n"        }    }    buildTypes {        release {            zipAlignEnabled true            shrinkResources true            minifyEnabled true            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')) {                        // 输出apk名称为guojinbao_v1.0_2015-01-15_wandoujia.apk                        def fileName = "guojinbao_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"                        output.outputFile = new File(outputFile.parent, fileName)                    }                }            }        }    }    // 友盟多渠道打包    productFlavors {        umeng {}        sjzs_360 {}        sjzs_bd {}        sjzs_91 {}        yyb {}        xmsd {}        hwyy {}        pp_azzs {}        oppo_sd {}        wdj {}        anzhi {}        anzhuosc {}        anzhuoyuan {}        jfw {}        lxlsd {}        mmy {}        yiyonghui {}        yingyonghui {}        yysc {}        kuchuan {}        sg_sjzs {}        wy_yyzx {}        ltwo {}        azsc_3g {}        sn_yysd {}        ndw {}        meizu {}        azzj {}        tykj {}        mmsh {}        lqsc {}        xlyy {}        anzhuosd {}        alsc {}        mgsc {}        tongbutui {}        vivo_sjzs {}        tyyy {}        kupai {}        zx_yysd {}    }    productFlavors.all { flavor ->        flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]    }
3,使用android studio右侧gradle功能


注意这里是app目录下

更多相关文章

  1. NPM 和webpack 的基础使用
  2. [APP] Android(安卓)开发笔记 006-使用短信验证SDK进行短信验证
  3. Android(安卓)5.x特性概览二
  4. android listview custom style 自定义样式
  5. android:制作system.img(yaffs2)镜像
  6. Android读取Excel文件
  7. Android(安卓)Manifest文件中meta-data的配置读取
  8. Android(安卓)tabhost让选中项加上背景图
  9. android与.NET webservice

随机推荐

  1. Android studio 使用AIDL 无法import cla
  2. android 常用小知识点 tips (二)
  3. Android button靠右侧显示
  4. [置顶] Android(安卓)Multimedia框架总结
  5. Android开发:设置widget大小为 4x1
  6. mmm和mm出现No private recovery resourc
  7. Android底层和中间层共同学习系列之andro
  8. Android上MediaScanner是如何工作的
  9. Android Bundle类---activity之间通信
  10. Android 代码混淆 选项说明