从apk中的android库中删除不需要的资源

时间:2013-11-06 19:58:59

标签: android ant build shared-libraries

我有一个共享库,由应用程序的多个方差使用。我希望能够根据应用配置删除未使用的库资源。

  • 我不想永久删除资源,因此Lint没有帮助
  • 资源由共享代码引用,我只知道在某些差异中,不使用相当大的块
  • 正在使用引用资源的共享代码(仅在某些使用差异中,一个相当大的块不在播放中)所以proguard也无济于事

我正在使用ant构建脚本向hackery移除它以从库jar中删除它。还有其他想法吗?

2 个答案:

答案 0 :(得分:0)

找到我的解决方案,使用属性aapt.ignore.assets删除最终apk中我不想要的内容。剪辑自sdk r22 tools / ant / build.xml

    <!-- 'aapt.ignore.assets' is the list of file patterns to ignore under /res and /assets.
     Default is "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"

     Overall patterns syntax is:
       [!][<dir>|<file>][*suffix-match|prefix-match*|full-match]:more:patterns...

     - The first character flag ! avoids printing a warning.
     - Pattern can have the flag "<dir>" to match only directories
       or "<file>" to match only files. Default is to match both.
     - Match is not case-sensitive.
-->
<property name="aapt.ignore.assets" value="" />

此属性的意外副作用是它在“code-gen”期间也会被使用,并且不会生成drawable id并且proguard会抱怨。您需要在配置中添加dontwarn。

您还希望将这些资源包装到自己的类中,当资源不在时,不会调用它们。因为如果它们在一个公共类中,即使没有使用,java静态初始化程序也会崩溃,试图将它们链接起来。

答案 1 :(得分:0)

排除来自.apk 版本的整个./www/app目录

<property name="aapt.ignore.assets" value="&lt;dir&gt;app:" />