Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change android app name in the build gradle file

I'm creating different flavors using gradle for 2 small android apps ,i wanna just know if i can edit app name on the xml file in the build.gradle , for my different flavors .

like image 397
wissem46 Avatar asked Nov 28 '22 13:11

wissem46


2 Answers

What do you mean by app name? the application package name in the manifest or the application name as it appears in the launcher?

If the former, do:

android {
  productFlavors {
    flavor1 {
      packageName 'com.example.flavor1'
    }
    flavor2 {
      packageName 'com.example.flavor2'
    }
  }
}

It's possible to override the app name as well but you'd have to provide a flavor overlay resource instead.

So create the following files:

  • src/flavor1/res/values/strings.xml
  • src/flavor2/res/values/strings.xml

And in them just override the string resource that contains your app name (the one that your manifest use for the main activity label through something like @string/app_name). You can also provide different translations as needed.

like image 70
Xavier Ducrohet Avatar answered Dec 04 '22 19:12

Xavier Ducrohet


You can use resValue, eg.

debug {
    resValue 'string', 'app_name', '"MyApp (Debug)"'`
}
release {
    resValue 'string', 'app_name', '"MyApp"'
}

Make sure your AndroidManifest uses android:label="@string/app_name" for the application, and remove app_name from strings.xml as it will conflict with gradle's generated strings.xml when it tries to merge them.

like image 41
Tom Avatar answered Dec 04 '22 17:12

Tom