Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从apk中的android库中删除不需要的资源_Android_Ant_Build_Shared Libraries - Fatal编程技术网

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

从apk中的android库中删除不需要的资源,android,ant,build,shared-libraries,Android,Ant,Build,Shared Libraries,我有一个共享库,可供应用程序的多个变体使用。我希望能够根据应用程序配置删除未使用的库资源 我不想永久删除资源,所以Lint没有帮助 这些资源是由共享代码引用的,我只知道在某些情况下,不会使用相当大的块 引用资源的共享代码正在被使用(只是在特定的使用差异中,一个相当大的块没有发挥作用),因此proguard也没有帮助 我正准备使用ant构建脚本将其从库jar中删除。还有其他想法吗?找到了我的解决方案,使用属性aapt.ignore.assets退出我在最终apk中不想要的任何内容。从sdk r

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

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

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

找到了我的解决方案,使用属性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静态初始值设定项也会在尝试链接它们时崩溃。

将整个
/www/app
目录从.apk构建中排除:


你看过Gradle吗?:是的,我一直在使用Gradle系统进行较小的、不重要的项目,并且非常喜欢它。然而,在事情变得更稳定之前,我还不能转换我的主要制作轨道。