Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App Bundle with in-app locale change

I've a problem with AAB when I need to change the app locale from within the app itself(i.e. have the language change setting inside the app), the issue is that the AAB gives me only my device languages resources, for example:

my device has English and French languages installed in it, so AAb gives me only the resources for English and French,

but from within the app itself there is a choice to switch the language between English, French, and Indonesian,

in that case, when changing the language to English or French everything is working perfectly, but when changing it to Indonesian, the app simply enters a crash loop as it keep looking for Indonesian language but it can't find.

The problem here is that even if I restarted the app, it enters the crash loop again as the app is still looking for the missing language resources, and here the only solution is to clear cash or reinstall which are the solutions that the normal user won't go through.


Just to mention it, this is how I change the locale through the app:

    // get resources     Resources res = context.getResources();     // create the corresponding locale     Locale locale = new Locale(language); // for example "en"     // Change locale settings in the app.     android.content.res.Configuration conf = res.getConfiguration();     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {         conf.setLocale(locale);         conf.setLayoutDirection(locale);     } else {         conf.locale = locale;     }     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {         context.getApplicationContext().createConfigurationContext(conf);     }     res.updateConfiguration(conf, null); 

P.S. The app is working perfectly when build it as APK.

like image 556
Muhammed Refaat Avatar asked Oct 10 '18 02:10

Muhammed Refaat


2 Answers

Edit:

The PlayCore API now supports downloading the strings for another language on-demand: https://developer.android.com/guide/playcore/feature-delivery/on-demand#lang_resources

Alternative solution (discouraged):

You can disable the splitting by language by adding the following configuration in your build.gradle

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         }     } } 

This latter solution will increase the size of the app.

like image 196
Pierre Avatar answered Sep 29 '22 05:09

Pierre


This is not possible with app bundles: Google Play only downloads resources when the device's selected languages change.

You'll have to use APKs if you want to have an in app language picker.

like image 42
ianhanniballake Avatar answered Sep 29 '22 04:09

ianhanniballake