具有应用内区域设置更改的Android App Bundle

问题描述 投票:14回答:2

当我需要从应用程序本身更改应用程序区域设置时(即在应用程序中有语言更改设置),我遇到AAB问题,问题是AAB只给我设备语言资源,例如:

我的设备中安装了英语和法语,所以AAb只给我英语和法语的资源,

但是从应用程序本身可以选择在英语,法语和印尼语之间切换语言,

在这种情况下,当将语言更改为英语或法语时,一切都运行良好,但是当将其更改为印度尼西亚语时,应用程序只需进入崩溃循环,因为它一直在寻找印尼语,但却无法找到。

这里的问题是,即使我重新启动应用程序,它也会再次进入崩溃循环,因为应用程序仍在寻找缺少的语言资源,这里唯一的解决方案是清理现金或重新安装哪些是普通用户赢得的解决方案不去。


只是提一下,这是我通过应用程序更改语言环境的方式:

    // 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);

附:该应用程序在将其构建为APK时工作正常。

android locale android-app-bundle
2个回答
23
投票

编辑:

PlayCore API现在支持按需下载另一种语言的字符串:https://developer.android.com/guide/app-bundle/playcore#lang_resources

替代解决方案(气馁):

您可以通过在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
        }
    }
}

后一种解决方案将增加应用程序的大小。


4
投票

对于应用包,这是不可能的:Google Play仅在设备选定的语言发生变化时下载资源。

如果你想要一个应用程序语言选择器,你将不得不使用APK。

© www.soinside.com 2019 - 2024. All rights reserved.