More fine-grained control of keeping/renaming classes/members

I’m not sure how to do some things with Proguard:

  • I’d like to be able to obfuscate some classes but not repackage them (while everything else is repackaged)
  • Alternatively, I’d like to be able to obfuscate members of classes without renaming (or repackaging) the class itself

Is there any way to do either of these? Thanks!

Hi @rdh ,

For the first question;
Please have a look at the option -keeppackagenames in the ProGuard manual. This option will allow you to preserve structure (and names) of the packages you specify in the filter;
e.g. -keeppackagenames com.example.**

For the second question;
This can be achieved as shown below;
-keep class com.example.MyClass

Best regards,

Jonas

Hi Jonas,

Thanks for your quick response. The second answer works great, but the first isn’t quite what I need. -keeppackagenames stops classes in the specified package from being renamed, which I still want them to do. Essentially (in your language) I want to preserve the structure but not the names.

Hi @rdh ,

Thank you for your message.

The structure of the packages is modified when the option -repackageclasses or -flattenpackagehierarchy is set in any of the ProGuard configuration files. Please note this can be part of a default configuration file you’re using or consumer rules embedded in a dependency. Removing these options will result in ProGuard not changing the package structures.

The -keeppackagenames option will preserve the names of packages but not classes, I suspect there are some -keep rules that target classes in packages you observe not to be obfuscated.

Best regards,

Jonas

1 Like