码迷,mamicode.com
首页 > 移动开发 > 详细

android——利用gradle实现多渠道打包并自定义包名(umeng多渠道)

时间:2017-10-24 14:09:42      阅读:380      评论:0      收藏:0      [点我收藏+]

标签:ges   channel   包名   xml文件   and   asp   def   value   android   

1.首先在mainfest.xml文件中,给umeng_channel设置一个变量“${UMENG_CHANNEL_VALUE}

2.在gradle中,配置flavors。

 productFlavors {
        yingyongbao {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_txyyb"]
      
        }
        s360 {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_360"]
       
        }
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_baidu"]
     
        }
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_xiaomi"]
           
        }
        huawei {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_huawei"]
          
        }
        meizu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_meizu"]
          
        }
        lenovo {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_len"]
            applicationId ‘com.songheng.beijingtianqikuaibao‘
        }
        oppo {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_oppo"]

        }
        vivo {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_vivo"]

        }
        ali {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_ali"]

        }
        yingyonghui {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_yyh"]

        }
        sougou {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_sougou"]

        }
        anzhi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "bjtq_anzhi"]
        }
    }

3.可以直接签名打包了。

技术分享

这么打包,apk所在路径:项目路径\app\app-anzhi-release.apk 

4.自定义包名方式

  applicationVariants.all { variant ->
        variant.outputs.each { output ->
            if (‘release‘.equals(variant.buildType.name)) {
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) {

                    def buildLable = ""
                    def buildName = ""

                    // 是否是连接测试服务器版本
                    if (rootProject.hasProperty(‘TestServer‘)) {
                        buildLable = "${buildLable}_Test"
                    } else {
                        buildLable = "${buildLable}_Product"
                    }
            //buildname 是channel名称
                    variant.productFlavors.each { product ->
                        buildName = product.name
                    }

                    // 是否是testin版本
                    if (rootProject.hasProperty(‘TestIn‘)) {
                        buildLable = "${buildLable}_TestIn"
                    }
                    def productName = "bjtqyb"
                    def fileName = "${productName}_v${defaultConfig.versionName}_${releaseTime()}${buildLable}_${buildName}.apk"
                    output.outputFile = new File("${rootDir}/outapks/", fileName)
                }
            }
        }
    }

 

android——利用gradle实现多渠道打包并自定义包名(umeng多渠道)

标签:ges   channel   包名   xml文件   and   asp   def   value   android   

原文地址:http://www.cnblogs.com/shoneworn/p/7722936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!