Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different app names for different build flavors?

Tags:

android

gradle

I have 2 build flavors, say, flavor1 and flavor2.

I would like my application to be named, say, "AppFlavor1" when I build for flavor1 and "AppFlavor2" when I build for flavor 2.

It is not the title of activities I want to change. I want to change the app name as it's displayed on the phone menu and elsewhere.

From build.gradle I can set various parameters for my flavors but, it seems, not the app label. And I can not change the app label programmatically based on some variable, too.

So, how do people handle this?

like image 545
Alexander Kulyakhtin Avatar asked Nov 07 '13 08:11

Alexander Kulyakhtin


People also ask

What are app flavors?

Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.

What are build flavors?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

What are build types?

Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.

What is a build type and a product flavor in Android?

Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”. Product Flavors specify different features and device requirements, such as custom source code, resources, and minimum API levels.


1 Answers

Remove app_name from strings.xml (else gradle will complain of duplicate resources). Then modify build file like this:

productFlavors {     flavor1{         resValue "string", "app_name", "AppNameFlavor1"     }      flavor2{         resValue "string", "app_name", "AppNameFlavor2"     }    }  

Also make sure @string/app_name value is assigned for android:label attribute in the manifest.

<application         ...         android:label="@string/app_name"         ... 

This is less disruptive than creating new strings.xml under different built sets or writing custom scripts.

like image 68
Ganesh Krishnan Avatar answered Dec 12 '22 23:12

Ganesh Krishnan