Changing output apk name and add version name

suggest change

This is the code for changing output application file name (.apk). The name can be configured by assigning a different value to newName

android {
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def apk = output.outputFile
            // Build the name inside the loop. A name accumulated outside
            // grows once for every output.
            def newName = "ApkName-v" + defaultConfig.versionName
            if (variant.buildType.name == "release") {
                newName += "-release.apk"
            } else {
                newName += ".apk"
            }
            if (!output.zipAlign) {
                newName = newName.replace(".apk", "-unaligned.apk")
            }

            output.outputFile = new File(apk.parentFile, newName)
            logger.info("INFO: Set outputFile to "
                        + output.outputFile
                        + " for [" + output.name + "]")
        }
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents