33

I have used the latest android packing format bundle and shipped my app to beta channel,bundles reduced ~60% of app size which was really awesome ,

my app has support for english and arabic (can be switched within the app on fly)

now the problem : AFAIK the base apk will only have resources for the users language during app download (if at time of download,if the language was english.only string-en.xml gets downlaoded)

so how do i handle the situation where in user switch the language within the app ..

please let me know..

ashif-ismail
  • 1,037
  • 17
  • 34

3 Answers3

46

AFAIK you can do it by using the bundle block to control which types of configuration APKs you want your app bundle to support.

Based on the documentation:

android {
    
    ...
    bundle {
        language {
            // Specifies that the app bundle should not support
            // configuration APKs for language resources. These
            // resources are instead packaged with each base and
            // dynamic feature APK.
            enableSplit = false
        }
    }
}
Janusz
  • 187,060
  • 113
  • 301
  • 369
Sagar
  • 23,903
  • 4
  • 62
  • 62
  • i guess,this will be having a negative impact on app size then...??wont this ? – ashif-ismail Jun 27 '18 at 05:21
  • @al_mukthar Its your requirement right? It will add all the string resources and might result in increase of size – Sagar Jun 27 '18 at 05:56
  • its ok if its around ~2mb ..will it go above this ? – ashif-ismail Jun 27 '18 at 06:59
  • 1
    @al_mukthar It all depends on the number of strings you have and number of locale you support. Check out [this blog](https://medium.com/google-developers/smallerapk-part-3-removing-unused-resources-1511f9e3f761) for more details. – Sagar Jun 27 '18 at 07:53
  • thanks sagar for pointing in the right direction,ingfact i have only one locale extra,ie arabic..and resources are not that big to increase the app size too much...accepting your answer.. – ashif-ismail Jun 28 '18 at 03:54
  • This still works but the documentation is pretty hidden: https://developer.android.com/guide/app-bundle/configure-base#disable_config_apks – Janusz Oct 28 '20 at 14:25
10

With the Play Core library version 1.4.0, you can request the Play Store to install resources for a new language configuration on demand and immediately start using it.

// Creates a request to download and install additional language resources.
SplitInstallRequest request =
    SplitInstallRequest.newBuilder()
        // Uses the addLanguage() method to include French language resources in the request.
        // Note that country codes are ignored. That is, if your app
        // includes resources for “fr-FR” and “fr-CA”, resources for both
        // country codes are downloaded when requesting resources for "fr".
        .addLanguage(Locale.forLanguageTag("fr"))
        .build();

// Submits the request to install the additional language resources.
splitInstallManager.startInstall(request);

For more informations: https://developer.android.com/guide/app-bundle/playcore#lang_resources

Simon
  • 1,890
  • 19
  • 26
3

Currently I only find that by changing the device language in the system settings, your app will automatically download the additional language APK from Play Store given that you have included that language's resource in your app bundle. Still trying to find if I can manually submit a request for additional language through PlayCore Library within my app...

littledog
  • 258
  • 2
  • 14
  • 2
    Did you find a solution to trigger the download of the language manually? – chrisonline Oct 18 '18 at 14:34
  • 2
    I've asked Google about this. Currently you can't. But they say they are working on it, and will add this feature in the future. – littledog Oct 19 '18 at 02:24
  • 1
    What happens with no connectivity? Assuming new lang is delayed in this case. – Vairavan Jan 30 '19 at 22:15
  • Yes the downloading will be postponed at some point later. But this is handled by the Play Framework, so we don't really know when exactly. – littledog Jan 31 '19 at 05:28