Friday, December 29, 2023

Jackson vs. Android package optimization

 For some weird reason (including a 20MB text file to be precise) I wanted to turn on 

shrinkResources true
minifyEnabled true

in my Android app.
I did the compression alright, but the app stopped working.
I got weird Exceptions like 
Cannot construct instance of `g1.k` (no Creators, like default ...)

Well that pointed me to obfuscation, because I definitely don't have classes and members like that.

Jackson relies on reflection to find your class properties and getter/setter functions, so you should not obfuscate them. Duuuh.

They way to turn that off is in the file.

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep public class** {

The last part keeps the whole package where all my entity classes are.