chris
chris

Reputation: 313

Differences in simple proguard keep option

What is the difference between these two proguard options?

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

Upvotes: 1

Views: 549

Answers (2)

Zircon
Zircon

Reputation: 4707

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

Upvotes: 1

T. Neidhart
T. Neidhart

Reputation: 6200

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.

Upvotes: 1

Related Questions