Search code examples
androidgsonproguardandroid-proguardandroid-security

Is it possible to obfuscate Strings in GSON Annotations while using ProGuard?


i am trying to shrink, optimize and obfuscate my application with ProGuard. Everything works fine except GSON annotations. I have something like this in my application:

@Expose
@SerializedName("testbla")
private String test;

And when im using ProGuard it turns into something like this:

@com.google.a.a.a
@c(a="testbla")
private String a;

So there is some kind of obfuscation but the "testbla" is still readable. Ive read in the documentation that String constants wont get obfuscated by ProGuard (e.g. https://www.guardsquare.com/en/proguard/faq#encrypt). Nevertheless i want to obfuscate those Strings if there is any option. So is there is any possibility then please let me know!

Thanks for your help!


Solution

  • ProGuard doesn't obfuscate strings.

    The Gson annotation it's important to ensure that your mapping class will work fine.

    If you remove your annotation and use proguard, when your app needs convert your JSON to POJO an error will occur. Because the code will try to find the attribute "a" and not "test" (because your code is obfuscated). Because of this, the Gson annotation it's important.

    There're other options to obfuscate your code, like DexGuard, but it's not free.

    Check out the differences: Link