Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

renaming apk in gradle

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

applicationVariants.all { variant ->      
            def file = variant.outputFile
            def filename = file.name.replace("SomeXXX", "SomeYYY")
            variant.outputFile = new File(file.parent, filename)

                    }

This successfully renames the apks but not the unaligned apks. Please someone throw some light on this.

like image 570
Pulkit Sethi Avatar asked May 16 '14 05:05

Pulkit Sethi


1 Answers

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"))
    }
like image 71
Nebu Avatar answered Oct 12 '22 08:10

Nebu