How to get ProGuard to remove a public static method?

I have several classes in my application that provide methods public static void main(String[] args) . These methods are only needed during development / testing, and I would like ProGuard to remove them (but only these methods, not all the surrounding classes). I tried using -assumenosideeffects , but this only affects method calls, not the methods themselves. How to get Proguard to remove all main() methods, despite the fact that they are public and static ?

+6
source share
1 answer

ProGuard needs seeds to determine which classes / methods need to be stored. Everything indicated in these seeds will also be saved.

The -assumenosideeffects option -assumenosideeffects 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 being deleted.

In your particular case, you probably have a rule that supports all methods of public static void main(String[]) , since this will be the standard seed for a Java application.

You can analyze the reason for saving a particular method / class using the -whyareyoukeeping parameter.

0
source

Source: https://habr.com/ru/post/949104/


All Articles