Prevent Proguard child classes from being annotated

I have a class with Gson annotations that I need to avoid obfuscation through ProGuard. This bit of code works

public abstract class FacebookIdentifier {
    @Expose public String id;
    @Expose public String name;
}

-keepclasseswithmembers class * {
    @com.google.gson.annotations.* <fields>;
}

Now I have some classes that extend such classes without an extra field. Example:

class FacebookApplication extends FacebookIdentifier {}

Such a class is confusing, even though its parent has some annotations that prevent it from getting confused. Is there any way so that this class is not confused?

+4
source share
1 answer

You will need to specify the extension explicitly:

-keep class com.example.FacebookApplication

However, for JSON, class names probably don't matter; field names only. Saving fields should be sufficient:

-keepclassmembers class * {
    @com.google.gson.annotations.* <fields>;
}

, , GSON.

0

Source: https://habr.com/ru/post/1544292/


All Articles