Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App Name Per Build Type AND Flavour

My application is having multiple build types and flavours gradle.

buildTypes {
    release {}
    test {}
    debug {}
}
productFlavors {
    europe {}
    asia {}
}

How can I name the app according to the combination of build type and flavor?

Example:
Flavour europe will have app name AppEurope
BuildType test will add "Test" suffix behind the app name, AppEuropeTest

like image 496
Mark KWH Avatar asked Feb 07 '23 15:02

Mark KWH


1 Answers

I was facing the same problem within my watch face and tried to combine flavor dependent application names with build type dependent application label values. I ended up doing it as follows:

  1. Use manifestPlaceholder in the build.gradle to inject buildType specific string resource links:

In the build.gradle file:

buildTypes {
  release {
    manifestPlaceholders = [ applicationLabel: "@string/app_name"]
  }
  debug {
     manifestPlaceholders = [ applicationLabel: "@string/app_name_dev" ]
  }
}

In the AndroidManifest.xml:

<application
   [..]
   android:label="${applicationLabel}">

In the strings.xml file:

<resources>
  <string name="app_name">Classic &amp; Essential</string>
  <string name="app_name_dev">Classic &amp; Essential (DEV)</string>
</resources>
  1. Use flavor specific versions of string.xml resource files overriding the values for the flavor.

I also described this in one of my blog posts: https://www.journal.deviantdev.com/android-build-type-app-name-label/

like image 96
Rubberducker Avatar answered Feb 13 '23 06:02

Rubberducker