Android apk 构建的条件资源包含/排除 [英] Conditional resource inclusion/exclusion for Android apk build

查看:46
本文介绍了Android apk 构建的条件资源包含/排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直回到这个问题,因为似乎没有一个干净的解决方案.有没有人有从 Android 中的子项目中排除资源的好策略?

I keep coming back to this problem, since there doesn't seem to be a clean solution. Does anyone have a good strategy to exclude resources from a child project in Android?

我有两种情况:

1 - 基础库项目具有 en、es 等的本地化文件.

1 - Base library project has localization files for en, es, etc.

--子项目1使用了所有本地化,一切都很好

--Child project 1 uses all localizations, and everything is good

--子项目 2 仅本地化为英语,但最终的 .apk 将由于父资源而进行部分本地化(尽管 ADT19 左右添加了 Lint 规则以警告/阻止您这样做).

--Child project 2 is only localized to English, but the final .apk would have a partial localization due to the parent resources (although ADT19 or so added Lint rules to warn/prevent you from doing this).

我现在唯一的解决方案是为本地化创建一个单独的父库,并且只将其包含在子项目 1 中.如果您有很多库项目,这会很痛苦.

The only solution I have to this right now is to have a separate parent library for the localization, and only include it in child project 1. This is a big pain if you have lots of library projects.

2 - 排除特定于构建的资源.我有一些图像,只有我的应用程序的 Nook 特定版本才需要,这些图像由标志触发.条件代码效果很好,但资源总是包含在内.

2 - Exclusion of build-specific resources. I have a few images that are only needed for my Nook-specific builds of my apps, which are triggered by a flag. Conditional code works great, but the resources are always included.

我不想为我的每个应用程序创建另一个子项目.有没有办法设置构建/编译标志来修剪特定的图像资源,这样它们就不会进入最终的 .apk?

I'd prefer not to create yet another child project for EVERY ONE of my apps. Is there any way to set a build/compile flag to prune specific image resources out so they don't get into the final .apk?

第二个问题可能是我特有的,但我很惊讶我找不到关于第一点的任何好的讨论.没有其他开发人员只本地化一些应用程序吗?还是大多数人只是忽略了这个问题?

The second problem may be specific to me, but I'm surprised that I can't find any good discussion on the first point. Are no other devs localizing only some apps? Or are most folks just ignoring the issue?

推荐答案

1 - 基础库项目具有 en、es 等的本地化文件.

1 - Base library project has localization files for en, es, etc.

您有两个项目在使用这个库,其中只有一个需要所有的翻译.因此,这些翻译可能在使用库并需要翻译的项目中,而不是在库本身中.这与自定义库资源的任何其他项目(例如,替换图标、替换布局)没有什么不同.

You have two projects using this library, and only one of them needs all the translations. Hence, those translations could be in the project using the library and needing the translations, not in the library itself. This is no different than any other project customizing resources of a library (e.g., replacing icons, replacing layouts).

现在,一旦您开始进行更复杂的混合(例如,两个项目需要翻译而第三个不需要),那么您就会开始遇到问题.

Now, once you start getting into more complicated mixes (e.g., two projects need the translations and a third does not), then you start running into problems.

排除特定于构建的资源.我有一些图像,只有我的应用程序的 Nook 特定版本才需要,这些图像由标志触发.条件代码效果很好,但资源总是包含在内.

Exclusion of build-specific resources. I have a few images that are only needed for my Nook-specific builds of my apps, which are triggered by a flag. Conditional code works great, but the resources are always included.

Xav 和我聊了一些关于条件资源在这个问题中.他的重点是调试与生产(资源相当于 BuildConfig.DEBUG),但听起来更灵活是可能的.

Xav and I chatted a bit about conditional resources in this issue. His focus is on debug vs. production (resource equivalent to BuildConfig.DEBUG), but it sounds like something more flexible is a possibility.

这两件事都可以由自定义发布构建脚本处理.在正常的调试版本中,您可以不理会它;在生产版本中,在编译、签名和 zipaligning 之前,让 Ant 脚本处理项目的副本,修剪不需要的目录.

Both of these things could be handled by a custom release build script. In normal debug builds, you'd leave it all alone; in a production build, have an Ant script work off a copy of the project, trimming out directories that are not needed, before compiling, signing, and zipaligning.

这篇关于Android apk 构建的条件资源包含/排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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