Project folders and class names not getting obfuscated

Hi, for some reason the folders and class names are not getting obfuscated. Though the contents inside the class is getting obfuscated, I tried with new project and it doesn’t have any issues. Does structuring of the project affect obfuscating in any way?.

Hi @sunil_sunny ,

Welcome to the community!

Your ProGuard configuration may contain -keep rules which prevent ProGuard from obfuscating certain names. These -keep rules can come from your own configuration file but may also be picked up from a dependency you use (ProGuard consumer rules).

Furthermore, sometimes the option -dontobfuscate is (accidentally) set in the project, this prevents ProGuard from applying any form of obfuscation.

I’d recommend you to check out the ProGuard Playground, this tool visually shows you the effect of the -keep rules you have configured without the need to continuously (re)build the project.

Best regards,

Jonas

First of all thanks for taking your time and commenting it in detail. Rules were my doubt as well but even after removing all the rules it was the same. I can see lot of rules being added to aapt_rules which is autogenerated by AAPT. So it make sense that those classes are kept as it is. But my main concern is why even the folders are not obfuscated. Even with the dexguard it was the same, all folder names were easily readable.

Hi @sunil_sunny ,

If you keep a class, its package structure remains kept as well. By default, obfuscated classes are put in the o package by ProGuard. A package name will remain readable if at least one class in the package is kept.

Sometimes it’s possible to obfuscate a class name but not shrink/optimize it, in those cases you could opt for a keep rule as follows;
-keep,allowobfuscation class com.example

In the scenario above, the class name (and path) will still be obfuscated.

If none (or very little) of the classes are obfuscated, I’d recommend to carefully go over your -keep rules, they are likely too broad in that case. Addtionally look for the -dontobfuscate option, this may be set in the coinsoler rules of a dependency. The option -printconfiguration can be used to obtain all rules currently picked up by ProGuard.
Combined with the ProGuard Playground you can easily determine what’s preventing these classes/packages not to be obfuscated.

Best regards,

Jonas

Thanks @jonas.gijbels I think I got the issue.
-keep,allowobfuscation class com.example
In my case I think this is the way to go, thanks a lot for that.

2 Likes