EventBus报错:its super classes have no public methods with the @Subscribe annotation

使用EventBus时会出现its super classes have no public methods with the @Subscribe annotation,

在源码中可以看到是因为1、没有注解,2、反射得到为空

EventBus报错:its super classes have no public methods with the @Subscribe annotation_第1张图片

 

可以通过以下方式解决:

1、在回调方法没有添加注解,添加注解即可
EventBus报错:its super classes have no public methods with the @Subscribe annotation_第2张图片

2、因为混淆问题导致,在proguard-rules.pro中添加保留

-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe ;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    (java.lang.Throwable);
}

 

你可能感兴趣的:(android)