android tutorial - Changing output apk name and add version name | Developer android - android app development - android studio - android app developement



Changing output apk name and add version name:

  • 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 ->
        def newName = "ApkName";
        variant.outputs.each { output ->
            def apk = output.outputFile;

            newName += "-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 + "]");
        }
    }
}
click below button to copy code from our android learning website - android tutorial - team

Related Searches to Changing output apk name and add version name