Keep annotated class in Proguard

一个人想着一个人 提交于 2019-12-20 10:34:10

问题


I have a bunch of classes that use e.g. an @Singleton annotation like so

@Singleton
public class ImageCache

that I would like to keep. How can I configure a proguard -keep statement so it applies to all classes that have that annotation.

Btw in terms of context I need this for an app using Roboguice on Android, which is why I added the tags. Might help others.


回答1:


ProGuard is based on a java-like configuration with wild-cards. It does require fully qualified class names. This should work:

-keep @com.google.inject.Singleton public class *



回答2:


First define an annotation

public @interface DoNotStrip {}

Then put this in proguard.cfg:

-keep,allowobfuscation @interface com.something.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.something.DoNotStrip class *
-keepclassmembers class * {
    @com.something.DoNotStrip *;
}


来源:https://stackoverflow.com/questions/11622212/keep-annotated-class-in-proguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!