K.R.
K.R.

Reputation: 412

How to protect package-private and/or public classes from obfuscation by ProGuard?

I am looking at my current proguard configuration

-keep public class * extends android.app.Activity

and taking example from it, I created a marker interface ProtectedAgainstProGuard that I am going to use for all the classes I don't want obfuscated, in order to use such one-liner as the one mentioned above, rather than listing all the classes in the proguard file.

However, sometimes public classes will implement this interface, but sometimes package-private ones will implement it, so how do I state my rule?

a) -keep class * implements com.myapp.ProtectedAgainstProGuard

b) -keep public class * implements com.myapp.ProtectedAgainstProGuard

c) -keep class * implements com.myapp.ProtectedAgainstProGuard -keep public class * implements com.myapp.ProtectedAgainstProGuard

Upvotes: 0

Views: 734

Answers (1)

Shailesh Chandra
Shailesh Chandra

Reputation: 2340

Step 1: keep the interface, so that It doesn't get obfuscated

-keep interface com.myapp.ProtectedAgainstProGuard {*;}

Step 2: keep all the classes implementing this interface

-keep class * implements com.myapp.ProtectedAgainstProGuard { *; }

Upvotes: 1

Related Questions