使用EventBus,debug不报错,release版本报错:its super classes have no public methods with the @Subscribe annotat

出现该问题是因为未添加 EventBus的混淆,所以在Debug版本中不报错,但是却在Release版本报错;

解决方法:

在混淆文件“proguard-rules.pro”中添加

-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);
}



参考链接:http://greenrobot.org/eventbus/documentation/proguard/

https://stackoverflow.com/questions/35874055/eventbus-subscriber-class-and-its-super-classes-have-no-public-methods-with-th

总结:当出现该问题时,也是心里一顿急躁;并赶紧百度该问题,发现使用方法完全没问题但就是release版本报错,发现很多解答不能解决该问题,最后看到在stackoverflow上有人回复应该加混淆文件,才恍然大悟;并加上混淆之后发现功能正常。

其实在第一次出现该问题的时候就应该怀疑gradle文件的问题,因为配置中Debug和Release存在区别,一个加了混淆一个没加混淆。

所以遇到这种问题一定要思考两者是否存在什么区别,然后去解决问题而不是胡乱一堆搜索。既浪费时间又急躁。

猜你喜欢

转载自blog.csdn.net/andreaw/article/details/79090069
今日推荐