1. 程式人生 > >AndroidStudio/gradle 配置打包輸出檔名/輸出版本號渠道

AndroidStudio/gradle 配置打包輸出檔名/輸出版本號渠道

gradle 打包時候,我可可以指定輸出的檔名字,下面為例子版本號和版本名稱 加渠道

   applicationVariants.all { variant ->
        def application = "xxx"
        def buildName //渠道名字
        def outApkName //最終輸出檔名
        def outDir

        def versionName = 'v' + variant.getVersionName() //版本名稱
        def versionCode = 'c' + variant.getVersionCode()//版本號
variant.outputs.each { output -> variant.productFlavors.each { product -> buildName = product.name //獲取渠道名字 } outDir = output.outputFile.parent outApkName = application + '_' + versionName + '_' + versionCode + '_' + variant.buildType.name + buildName + '.apk'
output.outputFile = new File(outDir, outApkName) } } //多渠道 配置 渠道名字 上面的buildname取得是 名字 //xxx可以是渠道的key。 可以在AndroidManifest 用${UMENG_APPKEY}來獲取 productFlavors { _test { manifestPlaceholders = [UMENG_APPKEY: "xxx"] } _office { manifestPlaceholders = [UMENG_APPKEY: "xxx"
] } }

variant.buildType.name可以獲得是 debug打包還是 release方式打包。
這樣就輸出xxxv1.0_c1000_release/Debug_xxx

這樣就配置 自動打包的檔名字。