Saturday, January 03, 2026

Bad Ideas with Obfuscation

All my release versions of my Android apps are obfuscated with Proguard - which us quite usual.

However, it is a bad idea in some circumstances:

When you rely on reflection.

Sounds rather obvious, but sometimes you "dont know" this happens. Like when you serialize and deserialize JSON/XML data ("Rest") via Jackson
It is obvious, isn't it, but a couple of years ago it took me ages to find.

When you rely on class names.

Also rather obvious. What I did was have a listener class that will be asked if it wants to receive certain updates, and one of the parameters was the Class data that changed. Think of it like "Do you want to know if any of those Favorites changes?" and passing the "Favorite" class as a parameter,.
The listener has a 
public boolean wantsUpdatesFor(Class<?> clazz)
{
return Favorite.class.equals(clazz);
}
Worked fine in debug, didn't work in release. The main difference was of course obfuscation.
I removed it for those classes (or rather the whole package of them) et voilà worked again

Conclusion

If you find something works fine in debug but not at all in release, it's not always the emulator or its Android version or something like that, look at obfuscation was well and maybe remove it for a quick test.
(Or create a no-obfuscation build variant for that).