Android EventBus Subscriber class XXXActivity has no public methods called onEvent

Error message:

Caused by: c.a.a.g: Subscriber class XXXActivity has no public methods called onEvent.

There are two reasons for this error:

A: On the page that accepts Event, EventBus.getDefualt().register(this) is written, but in this page there is no definition of a method starting with onEvent, non-static, public permission, and only one parameter , that is There is no such method as: public void onEvent**(Object arg).

The solution is very simple, just check whether the page needs the onEvent**(Object arg) method. PS: Only on pages that need to receive EventBus messages, you should register EventBus.getDefault().register(this), and override a public method starting with onEvent, if you just simply send a message EventBus.getDefault(). post(bean); is not required to register.

B: If the inspection finds that the onEvent** (Object arg) method is indeed written, but an error is still reported, or the debug package is normal, but the Release package crashes, the reason is the confusion .

Solution: Just ignore the obfuscation of onEvent in your obfuscation file. The obfuscation methods of different versions may be a little different. Check the corresponding obfuscation method according to your eventBus version. ( EventBus github address )

Example: EventBus 2.4 obfuscation method:

-keep class de.greenrobot.event.** {*;}
-keepclassmembers class ** {
    public void onEvent*(**);
    void onEvent*(**);
}

The obfuscation method of EventBus 3.0:

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

So far the problem is solved. In the future, if the debug package is normal, but the release package crashes or is abnormal, most of them are the cause of confusion.

Daily record: A new year, a new start, everything is possible, so set a small goal for yourself, whether you can achieve it or not, first set up the Flag first.

I hope that in the new year, I can save more money, pass the Japanese N2 test, and learn a driver's license. Of course, I also need to improve my skills. come on! ! !

Single cycle "Triangle Chronicles"

Guess you like

Origin blog.csdn.net/androidzmm/article/details/104924342