【问题标题】:Remove not needed resources from android library in apk从apk中的android库中删除不需要的资源
【发布时间】:2013-11-06 19:58:58
【问题描述】:

我有一个共享库,供应用的多个变体使用。我希望能够根据应用配置剥离未使用的库资源。

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

我正准备使用 ant 构建脚本将其从库 jar 中删除。还有什么想法吗?

【问题讨论】:

  • 是的,我一直在将 gradle 系统用于较小的非关键项目,并且非常喜欢它。但是,在事情变得更稳定之前,我还不能切换我的主要制作曲目。

标签: android ant build shared-libraries


【解决方案1】:

找到我的解决方案,使用属性 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="" />

此属性的意外副作用是它在“代码生成”期间也被使用,并且不会生成可绘制 id 并且 proguard 会抱怨。您需要将 dontwarn 添加到您的配置中。

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

【讨论】:

    【解决方案2】:

    排除整个./www/app目录来自.apk构建:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 2016-09-20
      相关资源
      最近更新 更多