Differences in simple proguard keep option

2019-06-01 19:31发布

What is the difference between these two proguard options?

 -keep class com.myclass.**
 -keep class com.myclass.** { *; }

标签: java proguard
2条回答
神经病院院长
2楼-- · 2019-06-01 19:50

The first rule will only keep the classes themselves (and the default constructors).

The second rule will also keep all methods and fields in the classes.

查看更多
We Are One
3楼-- · 2019-06-01 19:50
-keep class com.myclass.**

Preserve all classes in the com.myclass package and any sub-packages. Even if shrinking and optimization steps should alter the structure of or remove these classes, do not do so.

-keep class com.myclass.** { *; }

Preserve all classes in the com.myclass package as defined above as well as all fields and methods in those classes.

An example of the difference: With the first command, my entry point methods (such as main) can still be shrunk, optimized, and obfuscated. In order to keep the signatures of those methods intact, I can specify the methods or fields I need to keep (or just the wildcard * as you did, though I would think that's too broad). This is essential for reflection and other situations where signatures and names must be kept intact.

Note that -keepnames and similar commands also keep the signatures, but only if they weren't already removed during shrinking.

查看更多
登录 后发表回答