Menu ▾ ▴

#656 Using annotations for Keep directive does not keep them during optimization

v5.3.3
open-works-for-me
None
5
2017-08-15
2017-07-14
No

I use annotation like @Keep to keep classes, methods and fields that are used only with reflection. But, the annotations seem not to be respected during optimisation.
The attached example only works if the class “test.ColorIntAdapter” is kept explicitly, but not when kept via annotations: constructor and methods are removed:

@KeepPublicClassMembers
public class ColorIntAdapter extends IntAdapter<Color>
{
    @Keep
    public ColorIntAdapter()
    {
    }

    @Keep
    @Override
    public int toInt(Color t) {
        return t.getRGB();
    }

}

Some parts of the config:

-keepclassmembers class * {
    @proguard.annotation.Keep *;
}
-keepclassmembers @proguard.annotation.KeepPublicClassMembers class * {
    public *;
}

(But maybe I misunderstood the documentation - you may correct my config)

1 Attachments

Discussion

  • Eric Lafortune

    Eric Lafortune - 2017-08-15

    Sorry about the delay... The annotation KeepPublicClassMembers corresponds to the option -keepclassmembers. It specifies to keep all public class members (fields and methods) of the annotated class -- not necessarily the annotated class itself. You should specify Keep, which corresponds to -keep -- they keep the annotated class. The Keep annotations on the methods already keep the methods.

     
  • Eric Lafortune

    Eric Lafortune - 2017-08-15
    • status: open --> open-works-for-me
     

Log in to post a comment.