Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force ProGuard to remove public static method?

Tags:

java

proguard

I have multiple classes in my application that provide public static void main(String[] args) methods. These methods are only required during development / testing, and I'd like ProGuard to remove them (but only these methods, not the entire surrounding classes). I've tried to use -assumenosideeffects, but that only seems to affect calls to methods, not the methods themselves. How can I force Proguard to remove the entire main() methods despite them being public and static?

like image 772
sschuberth Avatar asked Jul 10 '13 09:07

sschuberth


1 Answers

ProGuard needs seeds to determine which classes/methods need to be kept. Anything referenced from these seeds will also be kept.

The -assumenosideeffects option is used to remove actual calls to methods whose result is not used in any way, but does not necessarily mean that the method itself is removed.

In your specific case, you probably have a rule that keeps all public static void main(String[]) methods as this would be the standard seed for a java application.

You can analyse the reason why a specific method/class is kept using the -whyareyoukeeping option.

like image 151
T. Neidhart Avatar answered Nov 20 '22 12:11

T. Neidhart