renaming apk in gradle

前端 未结 1 1503
时光取名叫无心
时光取名叫无心 2020-12-29 11:46

I wish to rename my apk from gradle. I have the following lines inside build

applicationVariants.all { variant ->      
            def file = variant.ou         


        
相关标签:
1条回答
  • 2020-12-29 12:36

    The gradle plugin has moved on since you posted this, however to get this working on with the current plugin (v1.0.0), you can use the following:-

        variant.outputs.each { output ->
            def alignedOutputFile = output.outputFile
            def unalignedOutputFile = output.packageApplication.outputFile
    
            // Customise APK filenames (to include build version)
            if (variant.buildType.zipAlignEnabled) {
                // normal APK
                output.outputFile = new File(alignedOutputFile.parent, alignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
            }
            // 'unaligned' APK
            output.packageApplication.outputFile = new File(unalignedOutputFile.parent, unalignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
        }
    
    0 讨论(0)
提交回复
热议问题