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

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

问题描述

我继续回来到这个问题,因为似乎没有成为一个干净的解决方案。有没有人有一个很好的策略,以从Android的一个子项目排除资源?

我有两种情况:

1 - 基本库项目具有本地化文件恩,胚胎等

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

- 子项目2只局限于英语,但最终.apk文件将有部分国产化,由于母公司的资源(虽然ADT19左右增加皮棉规则警告/ $ P $从做这个pvent你)。

唯一的解决方案,我有这个权利,现在是有本地化的单独母库,并且只包括在子项目1。这是如果你有很多库项目的一个很大的痛苦。

2 - 排斥构建特定资源。我有一个只需要我的Nook特定的一些图片构建我的应用程序,这是由一个标志触发。有条件的code的伟大工程,但资源总是被包括在内。

我preFER不创建另一个子项目为我的应用程序每次一片。有什么办法来设置一个构建/编译标志修剪特定的图像资源了,这样他们就不会进入最后的.apk文件?

第二个问题可能是特定于我,但我很惊讶,我无法找到的第一个点什么好讨论的。没有其他的开发者只是一些本地化的应用程序?或者,大多数人只忽略的问题?

解决方案
  

1 - 基本库项目具有本地化文件恩,胚胎等

您在使用本库中有两个项目,其中只有一个需要所有的翻译。因此,那些翻译可以使用库和需要翻译,而不是在库本身是在项目中。这比库任何其他项目的定制资源(如更换图标,替换布局)。

没有什么不同

现在,一旦你开始进入更加复杂的混合物(例如,两个项目需要翻译和第三没有),那么你就遇到了问题。

  

排除的建立特定资源。我有一个只需要我的Nook特定的一些图片构建我的应用程序,这是由一个标志触发。有条件的code的伟大工程,但资源总是被包括在内。

XAV和我聊了一些关于在此条件资源发行。他的重点是调试与生产(资源相当于 BuildConfig.DEBUG ),但它听起来象是更灵活的是一种可能性。

这两种东西可以通过自定义的发布版本的脚本进行处理。在正常的调试版本,你会离开它独自一人;在生产建设,有一个Ant脚本工作过该项目的一个副本,修剪掉那些不需要的目录,在编译之前,签约和zipaligning。

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?

I have two scenarios:

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

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

--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).

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

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

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

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天全站免登陆