Scot
Scot

Reputation: 542

Obfuscate Java protected elements using ProGuard

I am developing a library that consists of several individual classes that all work together to perform the function of the library. One of the classes then exposes a handful of public functions that all outside code to make use of the library.

Since the different classes need to interact, I put them all in the same package and have a lot of "protected" stuff (classes and functions).

The problem is that the ProGuard by default will not obfuscate these protected elements as there is a chance that they could later be combined with another class in the same package. I would like to prevent this, though, for security reasons.

So the question is, can I force ProGuard to obfuscate these protected elements in addition to the private ones?

To put it another way, is there a way to tell ProGuard "I am done adding stuff to this package, please obfuscate not only the private stuff within each class, but the protected stuff within the package"?

Thanks!

Upvotes: 2

Views: 2573

Answers (1)

Eric Lafortune
Eric Lafortune

Reputation: 45676

ProGuard obfuscates everything that isn't matching one of the -keep options in your configuration. E.g., from the ProGuard manual > Examples > A typical library:

-keep public class * {
    public protected *;
}

This specification keeps all public and protected classes, fields, and methods. ProGuard obfuscates anything else. If you want to obfuscate more, you have to specify fewer elements to keep, e.g. with one or more options like this one:

-keep public class mypackage.MyPublicClass {
    public void myPublicMethod();
}

You can use wildcards or other templates, as documented in the ProGuard manual.

So, by default, ProGuard obfuscates everything, unless you specify to keep some elements. ProGuard can't guess what you'd like to keep.

Upvotes: 7

Related Questions