如何轻松地从版本APK中添加的库中删除不必要的本地化资源 [英] How to easily remove unnecessary localization resources from added libraries in release APK

查看:95
本文介绍了如何轻松地从版本APK中添加的库中删除不必要的本地化资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序非常简单,不需要很多本地化.

My app is quite simple and does not need a lot of localization.

我提供了默认语言(英语)和德语-这是我一直想要并且将要提供的,因为该应用程序完全集中在德国.

I supply default language (in English) and German - this is all I ever want and will ever supply, as the app is completely focused in Germany.

当我最近添加Google Play服务库时,正如Google Play商店告诉我的那样,我面临的问题是,我的应用程序中已经添加了56种(!!!)语言.原因是:该库附带了我不想在我的应用程序中使用的更多语言资源.在其余的只有英语/德语的情况下,如果用法语弹出Google Play对话框根本没有任何意义.

As I recently added Google Play Services library, I face the problem that 56 (!!!) additional languages have been added to my app, as the Google Play Store tells me. Reason is: the library comes with many more language resources that I do NOT want in my app. It simply does not make any sense if a Google Play dialog pops up in French when the rest was only English/German.

我不想从库项目中手动删除资源,这很繁琐且容易出错.另外,也许我将有另一个依赖于同一个库的应用程序,在那里我想要更多的语言?

I do not want to manually delete resources from the library project, this is tedious and error prone. Plus, maybe I will have another app relying on the same library and there I want more languages?

所以-我该怎么做?

谢谢!

推荐答案

我了解您的问题,简单的解决方案是从库中删除所有其他语言,但是,您需要使用每个新版本的Google Play服务,如您所说,如果您需要其他应用程序中的其他语言,那也不是最好的选择.

I understand your problem, the easy solution is to remove all extra languages from the library but, you need to do it with every new version of Google Play Services, and as you says, if you need other languages in other apps, that wouldn't be the best option.

相反,请尝试强制您的应用默认使用德语或英语:

Instead try to force to your app to use German or English as default:

您需要将此代码添加到您的Application类中

You need to add this code in your Application class

@Override
public void onCreate() {
    super.onCreate();
    avoidOtherLanguages();
    // your code here
}

@Override
public void onConfigurationChanged() {
    super.onConfigurationChanged();
    avoidOtherLanguages();
    // your code here
}

public void avoidOtherLanguages() {
    if (!Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage()))
    {
        // when other than german, use english
        final Configuration configuration = getResources().getConfiguration();
        configuration.locale = Locale.ENGLISH;
        getResources().updateConfiguration( configuration, getResources().getDisplayMetrics() );
    }   
}

希望它对您有用!

在经过大量搜索之后,您想出了一个解决方案!如果您使用 gradle 作为构建系统,则可以在 build.gradle 文件中执行此操作:

Hi come up with a solution after a lot of googling! If you are using gradle as build system you can do this in your build.gradle file:

   .....
   defaultConfig {
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 75
    versionName "1.0.0"

    resConfigs "en", "de"
}
...

使用 resConfig 告诉gradle您仅在使用这些语言环境配置,您库中的所有其他语言都将被从APK包中删除!

use resConfig to tell gradle that you are only using these locales configuration, all other languages in your libraries will be stripped out of the APK bundle!

让我知道这是否对您有用!

Let me know if that worked for you!

这篇关于如何轻松地从版本APK中添加的库中删除不必要的本地化资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆