sschuberth
sschuberth

Reputation: 29791

How to force ProGuard to remove public static method?

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?

Upvotes: 7

Views: 2724

Answers (1)

T. Neidhart
T. Neidhart

Reputation: 6200

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.

Upvotes: 1

Related Questions