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

Posted shoneworn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android——利用gradle实现多渠道打包并自定义包名(umeng多渠道)相关的知识,希望对你有一定的参考价值。

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多渠道)的主要内容,如果未能解决你的问题,请参考以下文章

Android gradle实现多渠道号打包

Gradle 实现 Android 多渠道定制化打包

android -------- Gradle 多渠道打包

Gradle实战:Android多渠道打包方案汇总

Android Studio + gradle多渠道打包

ANDROID STUDIO系列教程六--GRADLE多渠道打包