Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 731
magneticMonster Avatar asked Sep 12 '11 19:09

magneticMonster


1 Answers

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.

like image 105
Eric Lafortune Avatar answered Oct 22 '22 21:10

Eric Lafortune