Search code examples
androidlocalizationandroid-productflavors

Android: How to get resource strings in build.gradle to support multiple flavors in multiple languages?


I am developing an Android app and I have following features.

  1. The app has multiple product flavors
  2. Some of the UX strings are specific to product flavors.
  3. All the product flavors will be in multiple languages.

I have defined product flavor specific strings in build.gradle but the issue is that those strings are not translatable. Is there any way, I can get resources from strings.xml in build.gradle. If not, then what is the best way to go about this issue?

Thanks in advance.

P.S. Downvote must be accompanied with reason.


Solution

  • You can use strings.xml in your flavor. You don't need to define the extra strings in the build.gradle. So the common strings will go into main/res/values/strings.xml. The flavor specific strings are going to go into "flavor"/res/values/strings.xml When you make your build the two strings are going to be merged together.

    As for the localization I assume you know how it works, but in short u create the values-xx in main and translate the common strings, and you do the same in the flavors too and translate the specific strings.