How can I tell proguard to assume a package is not used?

走远了吗. 提交于 2019-12-06 03:23:38

问题


I'm attempting to set up proguard for my Android project. We use some pieces of a netty library in our code and I'd like to use Proguard to completely remove the pieces of code that I know aren't used.

Is there some way to tell proguard to assume a package (or class) is never used and so should not be included in the output JARs? Note that I'm not talking about excluding some code from obfuscation (which is what the -keep configuration options do), I'm talking about completely removing a class from the output.

Edit: As suggested by pst below, I tried to use the -whyareyoukeeping argument to determine the code path that proguard uses to determine a class is used. It does not change the output of dozens of warnings.

I also attempted to use a file filter on -outjars as suggested by pst. This also resulted in no change as the algorithm still assumes the class will be loaded and the filter is only applied after the "used" classes are determined incorrectly.

To be clear: the warnings are coming from classes in 3rd party libraries that we are including in our Android project. We don't execute any code that will load these classes, and if proguard finds a code path where it does assume these classes are loaded, I would like to explicitly say that it does not use those classes.


回答1:


An alternative to specifying a filter on the outjars could be to specify a filter on the injars:

-injars in.jar(!unwanted/package/**)

This way, you won't unnecessarily drag in any classes that are referenced by this package, since the filtering is happening before any processing.

ProGuard will now warn about the missing classes, so you have to specify that it's ok:

-dontwarn unwanted.package.**

You should be careful with these options, since suppressing warnings does not necessarily make the problems go away. As pst wrote, you'll get NoClassDefFoundsErrors if you filter out classes that are actually required.



来源:https://stackoverflow.com/questions/7393247/how-can-i-tell-proguard-to-assume-a-package-is-not-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!