Keep rules seemingly being ignored

I’m trying to get ProGuard configured with our application, and either I don’t understand what the configuration should be doing, or it’s being ignored. I’m not sure which.

I know the configuration file is being picked up, because some changes take hold. But I’m finding it very hard to get -keep rules to work. Adding them in seems to have no effect a lot of the time.

In a fit of desperation, I’ve even tried:

-keepclassmembers class com.myapp.** {
  *;
}

Which I think should mean it won’t obfuscate any classes or class members defined underneath the com.myapp package - effectively the entire application. Note that I’ve also tried this with -keep rather than -keepclassmembers, and there is no difference.

However, this configuration option seems to have no effect. I have managed to get some more specific specifiers to work, but only after much effort. Others fail to work, and the classes continue to be obfuscated.

Passing --info to gradle allows me to view the output of the ProGuard run, but there’s no sign of errors. Using -printseeds seeds.txt shows me the list of things being obfuscated, which remains unchanged between runs (despite config changes, and despite deleting all the output jars to force them to be regenerated).

Is there a way to debug what my rules are actually matching to? I’m assuming that I’m doing something wrong, but I’m not seeing any feedback to help me figure out what it is.

Thanks.

Is it possible that the configuration, or the builds, are being cached somehow?

It’s almost as if changes aren’t being picked up until several clean/rebuild cycles later. After fiddling with reading docs, re-running builds, deleting the output etc, suddenly changes I made an hour ago have an effect.

Hi,

Welcome to the ProGuard Community! A good tool you can use to debug your keep rules is the ProGuard Playground. It allows you to visualize the effect your configuration has on your code without having to rebuild your application. You can upload your app to the ProGuard Playground and then add and adjust your keep rules and see in real-time if the class you targeted with your keep rule is kept in your app.

Here is the link to the ProGuard Playground.

Another helpful tool to generate keep rules is the -addconfigurationdebugging option. When you add this option to your ProGuard configuration file it will generate an instrumented build to allow ProGuard to find cases of reflection at run-time. The necessary -keeprules for your application will be outputted to the console as you test your application, you can then just copy/paste the suggestions from the console into your configuration file. Make sure to remove the -addconfigurationdebugging option from your configuration file after you’re done testing.

See this link in the manual for more information:

ProGuard does not cache any configurations or builds each ProGuard build is based on the most current configuration.

Best Regards,

Aissa

1 Like