记录——gradle2.x和3.x中构建apk包的文件名

2018-06-20  本文已影响0人  zbiext

gradle 2.x

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            File outputDirectory = new File(outputFile.parent);
            def fileName
            if (variant.buildType.name == "release") {
                // 输出apk名称为 包名_v1.0_2016-03-03.apk
                //fileName = "${defaultConfig.applicationId}_v${defaultConfig.versionName}_${packageTime()}}.apk"
                fileName = "${defaultConfig.applicationId}_${defaultConfig.versionName}_${packageTime()}.apk"
                //fileName = "qplus_${defaultConfig.versionName}_${packageTime()}.apk"
                //fileName = "${defaultConfig.versionName}_${packageTime()}.apk"
            } else {
                //fileName = "${defaultConfig.applicationId}_v${defaultConfig.versionName}_${packageTime()}_beta.apk"
                fileName = "${defaultConfig.applicationId}_${defaultConfig.versionName}_${packageTime()}_beta.apk"
                //fileName = "qplus_${defaultConfig.versionName}_${packageTime()}_beta.apk"
                //fileName = "${defaultConfig.versionName}_${packageTime()}_beta.apk"
            }
            output.outputFile = new File(outputDirectory, fileName)
        }
    }
}

gradle 3.x

android.applicationVariants.all { variant ->
    variant.outputs.all {
        if (variant.buildType.name == "release") {
            // 输出apk名称为 包名_v1.0_2016-03-03.apk
            //fileName = "${defaultConfig.applicationId}_v${defaultConfig.versionName}_${packageTime()}}.apk"
            outputFileName = "${defaultConfig.applicationId}_${defaultConfig.versionName}_${packageTime()}}.apk"
        } else {
            //fileName = "${defaultConfig.applicationId}_v${defaultConfig.versionName}_${packageTime()}_beta.apk"
            outputFileName = "${defaultConfig.applicationId}_${defaultConfig.versionName}_${packageTime()}_beta.apk"
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读