我可以将资源值排除在我的 Android 子项目中吗? [英] Can I exclude resource values from being built into my Android child project?

查看:59
本文介绍了我可以将资源值排除在我的 Android 子项目中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个与基础 Android 项目相关联的子 Android 项目.基础项目包括各种语言目录values-xx".

有没有办法专门将这些目录排除在子项目中?

即没有values-de"(德语字符串)的子项目.

解决方案

即使这个问题真的很老,你也可能从未发现过,所以就在这里.您需要的几乎是在 gradle build plugin 0.7 中实现的新 resConfig,尽管我似乎无法让它像我理解的那样工作.

来自:http:///tools.android.com/tech-docs/new-build-system/resource-shrinking#TOC-Res-Configs

分辨率配置

<块引用>

除了移除未使用的资源,您还可以使用AndroidGradle 插件的resConfigs"功能让它删除任何资源您的应用程序不需要的配置.

例如,假设您的应用程序中的消息未被翻译,都是英文的.如果您使用的是诸如Google Play 服务,您正在为所有这些库中的消息.当库中的功能是访问,这些将显示给用户.无论你喜欢那个,还是想让整个应用程序使用一种语言,这取决于您.但是如果您选择使用一种语言,或者更一般地说,只使用您的应用面向的语言,您可以在build.gradle 文件,然后在构建时所有其他语言都是丢弃(这将使您的 APK 更小,类似于资源收缩设施).

以下是您添加到 build.gradle 文件中的内容,例如,如果您想要将您的语言限制为英语和法语:

android {默认配置{...resConfigs "en", "fr"}}

<块引用>

你也可以添加 resConfigs "nodpi", "hdpi" 到例如限制打包的密度文件夹,一般情况下可以使用此工具来限制任何资源之间的捆绑资源文件夹限定符.

我有一个类似的问题 使用 resConfig 强制 Android 风格的语言环境 仍然没有找到它不工作的原因.我 也在 Android 中提交了一个错误.

I have a couple of child Android projects that are linked to a base Android project. The base project includes various language directories 'values-xx'.

Is there a way to specifically exclude these directories from being built into the child projects?

i.e. A child project without the 'values-de' (German strings.)

解决方案

Even if this question is really old, you might never have found this so here it is. What you need is pretty much the new resConfig implemented in gradle build plugin 0.7 although I can't seem to be able to make it work like I understood it should.

from: http://tools.android.com/tech-docs/new-build-system/resource-shrinking#TOC-Res-Configs

Res Configs

In addition to removing unused resources, you can also use the Android Gradle plugin's "resConfigs" feature to have it remove any resource configurations that you app does not need.

For example, let's say the messages in your application have not been translated and are all in English. If you are using a library such as Google Play Services, you are picking up translations for all of the messages in those libraries. When functionality in the library is accessed, those will be shown to the user. Whether you prefer that, or want to have the whole app use a single language, is up to you. But if you choose to have a single language, or more generally, just the languages your app is targeting, you can set that up in your build.gradle file, and then at build time all other languages are dropped (which will make your APK smaller, similar to the resource shrinking facility).

Here's what you add to your build.gradle file if you for example want to limit your languages to just English and French:

android {
    defaultConfig {
        ...
        resConfigs "en", "fr"
        }
}

You could also add resConfigs "nodpi", "hdpi" to for example also limit the density folders that are packaged, and in general you can use this facility to limit the bundled resources among any resource follder qualifier.

I have a similar problem Force locale for Android flavor with resConfig and still have not found why it is not working. I filed a bug in Android too.

这篇关于我可以将资源值排除在我的 Android 子项目中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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