EventBus - Subscriber Class And Its Super Classes Have No Public Methods With The @subscribe Annotation
Solution 1:
Please ensure these lines are in your proguard config file if you are using proguard for your builds.
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
Solution 2:
i think it is because onEvent inside MapClass.java has no parameter. Could you try with the expected parameter?
Solution 3:
I faced the same issue and after a long research got the solution for every case. This problem is due to absence of @Subscribe public method onEvent() inside the class which you are trying to register Event bus as
EventBus.getDefault().register(this). Presence of this function is mandatory if you register a class with Event bus
This can be in two situations
using progruad : progruad may modify name of method onEvent() due to which event bus is not able to find it. Put these lines inide your progruad rules
-keepattributes Annotation
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe ;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *;
}
- if you are not using progruard then definitely your class is missing the method onEvent() with @Subscribe annotation. This annotation with method is mandatory with EventBus version 3.0.0 so double check presence of this method inside your class.
Solution 4:
Just in case your code is like mine :p
I had to set the method as public because it's currently private.
Solution 5:
ProGuard
ProGuard obfuscates method names and may remove methods, which are not called (dead code removal). Because Subscriber methods are not directly called, ProGuard assumes them to be unused. So if you enable ProGuard minification, you must tell ProGuard to keep those Subscriber methods.
Use the following rules in your ProGuard configuration file (proguard.cfg) to prevent Subscribers from being removed:
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you usenter code heree AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
Post a Comment for "EventBus - Subscriber Class And Its Super Classes Have No Public Methods With The @subscribe Annotation"