Differences in simple proguard keep option

泪湿孤枕 提交于 2019-12-06 16:00:41

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.

-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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!