how to change android app name in the build gradle file

后端 未结 5 1605
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 07:28

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 flav

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 08:01

    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.

提交回复
热议问题