Compile an Android application with a different Application Name and Package Name

This was tested on Android Studio and with the source code for Telegram.

To change the package name for your build, an easy way would be to add a flavor of the app:


Under the section android {, add the following:

productFlavors {
        securechat {
            packageName "com.joel.telmsg"
            versionCode 20


This will take care of changing your package name so that you can install a second version of th same application.

Next, we will take care of the Application name shown in the icon menu:

In the tag, add the following:


, so that the final code looks like this:

<manifest xmlns:android=""

Now, in


tag, add the following:


to replace the existing android:label text.

To change the name of the output .apk file, add the following:

applicationVariants.all { variant ->

        def apk = variant.outputFile;
        def newName;

        newName =".apk", "-v" + defaultConfig.versionName + "-" + + ".apk");

        newName = newName
                .replace("-" +, "")
                .replace(, "droidzone");

        variant.outputFile = new File(apk.parentFile, newName);
        if (variant.zipAlign) {
            variant.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
        }'INFO: Set outputFile to ' + variant.outputFile + " for [" + + "]");

to Telegram/TMessagesProj/build.gradle

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.