Question

I'm having some issues while obfuscating code with ProGuard. Basically GSON library is giving me a pain.

So I thought about obfuscating just com.mypackages.* and do not obfuscate used libraries.

Is it possible?

How is this called? I'm kinda lost at obfuscation atm, and I couldn't find any examples about that.

Any tips are soo appreciated.

Edit:

java.lang.AssertionError
        at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(Unknown Source)
        at com.google.gson.internal.bind.TypeAdapters$26.create(Unknown Source)
        at com.google.gson.Gson.getAdapter(Unknown Source)

After adding

-keepnames class com.google.gson.** {*;}

Edit2: I kept trying new things like:

-keep class com.google.**
-keepnames class com.google.** {*;}
-keepnames enum com.google.** {*;}
-keepnames interface com.google.** {*;}

And no luck so far.

No correct solution

OTHER TIPS

The simplest way I can think of to keep the GSON library from being obfuscated is to add something like this to your ProGuard config:

-keepnames com.google.gson.** {*;}

With -keepnames, ProGuard's obfuscation step preserves the names of the specified classes, fields, and methods. ProGuard's shrinking step and optimization step may still remove the classes, fields, and methods themselves, if they appear unused. You want to use the more common -keep option:

-keep class com.google.gson.** { *; }

This line keeps the matching classes, fields, and methods, with their original names. It also matches interface classes and enum classes.

See the ProGuard manual > Usage > Overview of Keep Options

I too spent time struggling with this. In my case, it was not on the Gson side of things, but the enum that it was trying to deserialize (MyClass.MyEnum in this case). I used this:

-keep class com.google.gson.** { *; }
-keep enum com.abc.MyClass$MyEnum { *; }

Adding the second line above caused my code to make it past the problem and the application was functional again. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top