Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use flavors with different app names in Android studio?

In my app-level build.gradle I have the following flavors:

productFlavors {     originalFlavour{     }      freeFlavour{     } } 

The thing is building both flavors I get the same App Name. Instead I would like to have different app names for each flavors. Just adding a suffix would be useful. Hope someone could help me.

Thanks in advance

EDIT:

app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="z.fncapps.etsiipod"  >      <uses-permission         android:name="android.permission.CALL_PHONE"         android:required="false" />      <uses-feature         android:name="android.hardware.telephony"         android:required="false"/>      <application         android:allowBackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/AppTheme" >          <!-- actvities declared here -->     </application> </manifest> 

app/src/freeFlavour/AndroidManifest.xml

<uses-permission      android:name="android.permission.CALL_PHONE"     android:required="false" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  <uses-feature    android:name="android.hardware.telephony"    android:required="false" />  <application     android:allowBackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/AppTheme" >      <!-- actvities declared here --> </application> 

like image 998
fapps Avatar asked Feb 11 '15 22:02

fapps


People also ask

How do I use Android product flavors?

Android Product Flavors are used to create different app versions. App versions can be free or paid. They can have different themes and texts. They can use different environments or APIs.

Can we change app name in Android Studio?

Go to the app > manifests > AndroidManifest. xml file and change the android:label field in your application node in AndroidManifest. xml. As we can see in the Manifest.

Does app name need to be unique?

Choose a unique name First, it's important to ensure your name is unique. With millions of applications available in the digital world, many attractive app names are already taken. With this in mind, do your research and ensure nobody else is using the title you want.

What are product flavors in Android Studio?

So, product flavors allow you to output different versions of your project by simply changing only the components and settings that are different between them. Configuring product flavors is similar to configuring build types: add them to the productFlavors block of your project's build.


2 Answers

Remove the app_name string from your existing strings.xml file, then you can do this:

productFlavors {     originalFlavour{         resValue "string", "app_name", "Original Flavor Name"     }      freeFlavour{         resValue "string", "app_name", "Free Flavor Name"     } } 

Then the existing reference to @string/app_name in your manifest will refer to a generated string resource, which is based on the flavor selected.

Note that if you specify a label for your launch Activity (by defining the android:label xml tag in the <activity> element), that value will be used in many user-visible places rather than your application's label. To overcome this for your case, you can just remove the label from your <activity> element altogether. See https://stackoverflow.com/a/13200774/2911458 for more details on this distinction.

like image 167
stkent Avatar answered Sep 21 '22 17:09

stkent


You could use a string resource in AndroidManifest.xml:

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

And then use different values resource files for each flavor in ../app/src/ folder:

../app/src/

The key of this solution is that you could create localized strings.xml files inside each values folder for each flavor: /res/values/, /res/values-pt/, /res/values-es/, etc.

Each string.xml could have app name localized, the default (/res/values/) for Free Flavor Name could be:

<?xml version="1.0" encoding="utf-8"?> <resources>     <string name="app_name">Free Flavor Name</string> </resources> 
like image 45
crubio Avatar answered Sep 24 '22 17:09

crubio