I have annotated activity in a library that is a subscriber of an EventBus event from the same library. It looks something like this: greatly simplified:
@EActivity(resName = "activity_foo") public class Foo extends Activity { public void onEvent(BarEvent event){ doSomething(); } }
It should work in accordance with this:
http://timnew.me/blog/2014/09/14/otto-and-android-annotations-compatibility-issue-analysis/
But actually it returns with this error:
Cannot start activity ... de.greenrobot.event.EventBusException: Subscriber class com.foo.bar.activities.Foo_ does not have public methods called onEvent
EventBus doesn't seem to look in the parent class. I think the @Subscribe annotation everyone is talking about is only in Guava and Otto, but not in EventBus. No one talks about compatibility issues between AA and Eventbus on the network, so I am missing something.
How can I do this job?
EventBus: 2.4
AA: 3.2
EDIT
Following WonderCsabo's answer, I upgraded EventBus to version 3.0 (including subscription annotations) and AA to 3.3.1, and the problem went away, but there is one more:
java.lang.NoSuchFieldError at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:688) at libcore.reflect.AnnotationAccess.getDefaultValue(AnnotationAccess.java:361) at java.lang.reflect.Method.getDefaultValue(Method.java:327) at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75) at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112) at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94) at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:666) at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641) at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170) at java.lang.reflect.Method.getAnnotation(Method.java:301) at de.greenrobot.event.nb(SourceFile:133) at de.greenrobot.event.na(SourceFile:79) at de.greenrobot.event.ca(SourceFile:135) at com.babestudios.lib.lq.activities.f.onStart(SourceFile:515) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6006) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NoSuchFieldException: PostThread at java.lang.Class.getDeclaredField(Class.java:890) at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:685) at libcore.reflect.AnnotationAccess.getDefaultValue(AnnotationAccess.java:361) at java.lang.reflect.Method.getDefaultValue(Method.java:327) at libcore.reflect.AnnotationFactory.getElementsDescription(AnnotationFactory.java:75) at libcore.reflect.AnnotationFactory.<init>(AnnotationFactory.java:112) at libcore.reflect.AnnotationFactory.createAnnotation(AnnotationFactory.java:94) at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:666) at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641) at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170) at java.lang.reflect.Method.getAnnotation(Method.java:301) at de.greenrobot.event.nb(SourceFile:133) at de.greenrobot.event.na(SourceFile:79) at de.greenrobot.event.ca(SourceFile:135) at com.babestudios.lib.lq.activities.f.onStart(SourceFile:515) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6006) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
And I noticed that both problems (missing onEvent and now PostThread is only a problem in the release version. I use ProGuard with recommended exceptions for EventBus and AA).
EDIT 2 :
I added
-keep class de.greenrobot.** {*;}
and it seems to work.
source share