Java – Set ProGuard to obfuscate only my application packages

Set ProGuard to obfuscate only my application packages… here is a solution to the problem.

Set ProGuard to obfuscate only my application packages

Tried to obfuscate with ProGuard but got a 3rd party library error, so I’ll exclude each package one by one :

   -keepclassmembers class android.** {*; }
   -keepclassmembers interface android.** {*; }

-keepclassmembers class com.google.** {*; }
   -keepclassmembers interface com.google.** {*; }

Is there a way to whitelist only my package names?

com.dht.github.myApp

Solution

Depending on your code, you just keep the class members instead of the entire class.
Use it to keep the class as-is.

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

-keep interface com.google.** {*; }

You can also use this line to obfuscate only your own class and keep everything else.

-keep class !com.yourpackage.**,!com.youranotherpackage.** { *; }

Related Problems and Solutions