EventBus exception when proj is built - Subscriber class has no public methods called onEvent

3.1k views Asked by At

So, my app exchanges messages from/to my MainActivity to/from a background Service and I used EventBus to handle that. I'm registering both components with

EventBus.getDefault().register(this);

on their onCreates. And I'm sending/receiving an event with:

EventBus.getDefault().post(new MyMessagePojo("message"));

and

public void onEvent(MyMessagePojo event) { ... }

Everything works well when I run the project from my AndroidStudio right to my test phone. However, when I generated the signed APK I installed the app and got a crash with the following exception:

Subscriber class my.package.MainActivity has no public methods called onEvent

Where it clearly has. I tried changing it from onEvent to onEventMainThread in my MainActivity but with no success. It's pretty frustrating since I was about to publish the app and now I can't fix this problem.

I've been through this and this but they were of no help.

Any ideas?

2

There are 2 answers

1
han4wluc On BEST ANSWER

This is is addressed in the EventBus HOWTO docs. https://github.com/greenrobot/EventBus/blob/master/HOWTO.md

Use the below code to keep only the onEvent functions.

-keepclassmembers class ** {
    public void onEvent*(**);
}
0
Teo Inke On

So I managed to keep this method adding the following configuration on ProGuard:

-keep public class my.package.MainActivity {
    public <methods>;
}

However, ProGuard is messing up with more stuff on my app. I can't even login to my app (and I don't know why, I just get a Network Problem alert right away). I'm seriously considering to turn it off.