Search code examples
androidevent-bus

java.lang.RuntimeException: h.b.a.g: Subscriber class DashboardActivity and its super classes have no public methods with the @Subscribe annotation


I'm working on this application and i'm using EventBus 3.1.1 from greenbot. what i'm trying to is post event from fragment to activity.

What is weird is that my code is working just fine in debug mode, but when i build a release version it crashes when trying to register.

I have searched to find an answer and all came out as that the subscriber class shouldn't be the poster class, and in my case there is no problem regarding this matter.

here is my code:

in my fragment I'm calling:

EventBus.getDefault().post(new FireEvent());

in my activity:

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

@Override
protected void onStop() {
    if (EventBus.getDefault().isRegistered(this))
        EventBus.getDefault().unregister(this);
    super.onStop();
}

@Override
protected void onStart() {
    super.onStart();
    if (!EventBus.getDefault().isRegistered(this))
        EventBus.getDefault().register(this);
}

and then I Subscribe to the event:

@Subscribe(threadMode = ThreadMode.MAIN)
public void fireEvent(FireEvent event) {

}

Solution

  • based on @tidder answer i kept trying adding and removing rules and reached the below script which works perfectly.

    -keepattributes *Annotation*
    -keepclassmembers class * {
        @org.greenrobot.eventbus.Subscribe <methods>;
    }
    -keep enum org.greenrobot.eventbus.ThreadMode { *; }
    
    # Only required if you use AsyncExecutor
    -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
        <init>(java.lang.Throwable);
    }
    # EventBus 3.0
    -keep class de.greenrobot.event.** { *; }
    -keep class * {
        @de.greenrobot.event.* <methods>;
    }