1. 程式人生 > >Android studio中打包apk時去除debug|release

Android studio中打包apk時去除debug|release

//指定打包後應用名稱
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            def fileName
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                if (variant.buildType.name.equals('release')) {
                    fileName = "自己apk的名字${defaultConfig.versionName}_${defaultConfig.versionCode}.apk"
                } else if (variant.buildType.name.equals('debug')) {
                    fileName = "自己apk的名字${defaultConfig.versionName}_${defaultConfig.versionCode}.apk"
                }
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }