ProGuard配置greenrobot事件总线

时间:2017-07-14 06:27:58

标签: android android-proguard event-bus greenrobot-eventbus greenrobot-eventbus-3.0

我在我的应用程序中使用了eventbus,它在debuge模式下正常工作但没有处理发布APK。

以下用于ProGuard配置的代码:

  -keepattributes *Annotation*
  -keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
   }
  -keep enum org.greenrobot.eventbus.ThreadMode { *; }
  

我所有的订阅注释方法也是公开的

Logcat输出:

  

无法调度事件:class   com.dhaval.example.model.entity.response.DashboardUnreadStoryResponse   订阅班级   com.dhaval.example.view.activity.MainActivity                                                                  java.lang.NullPointerException:尝试调用虚方法   &#39; java.lang.String com.dhaval.example.model.entity.Dashboard.b.a()&#39;上   空对象引用                                                                      在com.dhaval.example.view.activity.MainActivity.b(SourceFile:150)                                                                      在com.dhaval.example.view.activity.MainActivity.onEventBusEvent(SourceFile:560)                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                      在org.greenrobot.eventbus.c.a(SourceFile:485)                                                                      在org.greenrobot.eventbus.c.a(SourceFile:420)                                                                      在org.greenrobot.eventbus.c.a(SourceFile:397)                                                                      在org.greenrobot.eventbus.c.a(SourceFile:370)                                                                      在org.greenrobot.eventbus.c.d(SourceFile:251)                                                                      在com.dhaval.example.view.a.r $ 1.a(SourceFile:140)                                                                      在com.dhaval.example.view.a.r $ 1.a(SourceFile:130)                                                                      在com.dhaval.example.f.ap $ 2.a(SourceFile:90)                                                                      在com.dhaval.example.f.ap $ 2.a(SourceFile:85)                                                                      在com.dhaval.example.network.a $ 1.a_(SourceFile:101)                                                                      在rx.c.a.a_(SourceFile:134)                                                                      at rx.internal.operators.n $ a.a(SourceFile:224)                                                                      在rx.a.b.b $ b.run(SourceFile:107)                                                                      在android.os.Handler.handleCallback(Handler.java:751)                                                                      在android.os.Handler.dispatchMessage(Handler.java:95)                                                                      在android.os.Looper.loop(Looper.java:154)                                                                      在android.app.ActivityThread.main(ActivityThread.java:6290)                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                      在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)07-14   11:39:43.640 16402-16402 / com.dhaval.example D / EventBus:没有订阅者   注册参加活动类org.greenrobot.eventbus.j 07-14   11:39:43.657 16402-16402 / com.dhaval.example   E / com.dhaval.example.view.a.r $ 1:getResponse出错:尝试   调用虚方法&#39; java.lang.String   com.dhaval.example.model.entity.Dashboard.b.a()&#39;在null对象上   参考

1 个答案:

答案 0 :(得分:1)

肯定听起来像proguard相关,但可能不是关于eventbus,而是关于你自己的model.entity.Dashboard类。可能需要将model.entity.Dashboard添加到proguard例外中:

-keep class model.entity.Dashboard.** { *; }