Hi,
I reopen the issue #656 as you did not understand me correctly.
I use annotation like @Keep to keep classes, methods and fields that are used only with reflection. However, the annotations seem not to be respected during optimisation. The class is self is used directly (via Annotations), so no keep declaration for the class needed.
The attached example only works if the public members of “test.ColorIntAdapter” are 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();
}
}
The error message is the following
Exception in thread "main" java.lang.InstantiationException: x.a
at java.lang.Class.newInstance(Unknown Source)
at test.Main.main(Unknown Source)
Caused by: java.lang.NoSuchMethodException: x.a.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 2 more
Therefore, the class is there but the constructor is removed that is used via reflection!
Some parts of the config:
-keepclassmembers class * {
@proguard.annotation.Keep *;
}
-keepclassmembers @proguard.annotation.KeepPublicClassMembers class * {
public *;
}
However, when I add this to the config is works correctly
-keepclassmembers class test.ColorIntAdapter {
public *;
}
Still happens with version 6.0.1
Confirm this issue on 4.7 (android SDK tools)
My class annotated with @Keep and not used directly, only by reflection (create new instance). And without @Keep (on constructor) constructor is shrinked (it can be detected by usage.txt also)
Last edit: Max Jackson 2018-06-28