Exclude some classes from Proguard conservation rules

I have a library that is going to get confused with ProGuard. "Library mode" is practically applicable for my use, i.e. It is almost normal to store all public and protected classes and class members. However, due to Java visibility requirements, some members cannot be private or private, and therefore they are public classes, although they should not be in the library. I would like them to be confused to make it clearer that these classes do not belong to the public api, as well as to improve obfuscation and small library jars. Is there a way to exclude some elements from the "hold" proguard rule without specifying each of these elements by name (using "!"). Ideally, I would like to annotate these classes and participants with tag annotations, but, as I understand it, Proguard can only report when elements with specific annotations are saved.

+4
source share
1 answer

You can only store items. If you want to exclude specific class members, you need to do this by specifying or annotating the class members that you want to keep. When specifying a class name, you can provide a list, optionally with "!" to exclude names. When specifying the name and type of a class member, this is not possible. However, in both cases, you can use wildcards. If you choose special names for your inner classes, this might work:

-keep public class * { public protected *** !myInternalField*; public protected *** !myInternalMethod*(...); } 
+4
source

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


All Articles