At some point as Android Devs we find ourselves with the case that our app supports only one or two languages, but we use libraries that support many languages (such as AppCompat, Google Play Services, Facebook SDK, etc.) so... we need to limit the languages supported by those libraries, why?

  1. The most obvious case, the user has German as default language in his/her device, our app only supports Spanish ... then the language with which our app presents the texts is Spanish BUT the library we use has resources for German in the values-de folder, so if that library shows a dialogue, that dialogue will be in German even though everything else in the app is in Spanish.
  2. The not so obvious case... Our app supports the user's default language and the library does as well, but that 3rd party library supports many other languages so it's importing all the resources for those languages into our APK, that causes our app to be unnecessarily heavier.

Anyways! the good news are that restricting the resources that these 3rd party libraries import into the APK is super easy using the resConfig and resConfigs options that we can configure in the default configuration or flavors of our app's build.gradle

defaultConfig {     
     resConfigs "es", "en" //if our app supports more than one language
     resConfig "es" //if our app support just one language (spanish for our example)

just by adding that to our gradle file, we prevent libraries from presenting texts in languages the app does not support, and at the same time we could reduce the size of the APK because we're making sure the 3rd party libraries won't add unnecessary resources into our build👌🏻🤓

Bonus Tip: Avoid using system strings at all costs, for example

@android:string/cancel //in xml files
android.R.string.cancel //in the code

Why? because those are resources that we cannot isolate, therefore the system will always translate them... and we might end up with a screen that is completely in Spanish but with some button saying Stornieren 😅

Thanks for reading the whole thing! 🏅👌🏻😃