简体   繁体   English

如何从Android中的第三方库中剥离冗余软件包?

[英]How to strip out redundant packages from 3rd-party libraries in Android?

I have an android app and a library , which uses Apache Commons Math. 我有一个android应用程序和一个 ,该使用Apache Commons Math。 Apache commons math is quite a fat library and it makes the output apk 1MB bigger. Apache Commons Math是一个丰富的库,它使输出apk增大1MB。

Since I am only using classes that are related to statistics and interpolation, I have two thoughts of how to reduce the size: 由于我仅使用与统计和插值相关的类,因此我对如何减小大小有两种想法:

  1. I would like to strip out unnecessary packages from the target apk (but how?) 我想从目标apk中删除不必要的软件包(但是如何?)
  2. The java-library which depends on apache commons can be a fat-jar (its jar-file will ie include all classes of apache-commons:math3 in it). 依赖apache commons的java库可以是一个胖jar(它的jar文件将在其中包含apache-commons:math3的所有类)。 I will exclude all unused packages from this jar. 我将从该jar中排除所有未使用的软件包。
  3. ProGuard? ProGuard? - don't want to use this at the moment -暂时不使用此功能

The first one seems the easiest, but I still don't know how to write a gradle task that removes unused packages. 第一个似乎最简单,但是我仍然不知道如何编写gradle任务来删除未使用的软件包。 Any examples or links will be appreciated. 任何示例或链接将不胜感激。 :) :)

As for the first option, since it's Apache Commons lib (distributed as open source), you can always create your own fork where you strip it from everything you don't need, recompile and use that recompiled version (make sure to change the version so that you don't accidentally run into any weird problems). 对于第一个选项,由于它是Apache Commons lib(作为开放源代码分发),因此您始终可以创建自己的fork,在其中将它从不需要的所有内容中剥离,重新编译并使用该重新编译的版本(确保更改版本)这样您就不会偶然遇到任何奇怪的问题)。 Probably not the best solution, though, but worth knowing as a last resort. 虽然可能不是最好的解决方案,但作为最后的手段值得一提。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM