1

I'm using eventbus into my application and it's working fine on debuge mode but not working on release APK.

Following code used for ProGuard configuration :

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

All my Subscribe-annotated methods are also public

Logcat output :

Could not dispatch event: class com.dhaval.example.model.entity.response.DashboardUnreadStoryResponse to subscribing class class com.dhaval.example.view.activity.MainActivity java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.dhaval.example.model.entity.Dashboard.b.a()' on a null object reference at com.dhaval.example.view.activity.MainActivity.b(SourceFile:150) at com.dhaval.example.view.activity.MainActivity.onEventBusEvent(SourceFile:560) at java.lang.reflect.Method.invoke(Native Method) at org.greenrobot.eventbus.c.a(SourceFile:485) at org.greenrobot.eventbus.c.a(SourceFile:420) at org.greenrobot.eventbus.c.a(SourceFile:397) at org.greenrobot.eventbus.c.a(SourceFile:370) at org.greenrobot.eventbus.c.d(SourceFile:251) at com.dhaval.example.view.a.r$1.a(SourceFile:140) at com.dhaval.example.view.a.r$1.a(SourceFile:130) at com.dhaval.example.f.ap$2.a(SourceFile:90) at com.dhaval.example.f.ap$2.a(SourceFile:85) at com.dhaval.example.network.a$1.a_(SourceFile:101) at rx.c.a.a_(SourceFile:134) at rx.internal.operators.n$a.a(SourceFile:224) at rx.a.b.b$b.run(SourceFile:107) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6290) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 07-14 11:39:43.640 16402-16402/com.dhaval.example D/EventBus: No subscribers registered for event class org.greenrobot.eventbus.j 07-14 11:39:43.657 16402-16402/com.dhaval.example E/com.dhaval.example.view.a.r$1: Error in getResponse: Attempt to invoke virtual method 'java.lang.String com.dhaval.example.model.entity.Dashboard.b.a()' on a null object reference

Dhaval Jivani
  • 9,467
  • 2
  • 48
  • 42
  • Too me it doesn't seem to be eventbus related. It's just a NPE in your own model.entity.Dashboard class. May be you need to add that model.entity.Dashboard into proguard exceptions: -keep class model.entity.Dashboard.** { *; } – shtolik Jul 14 '17 at 06:40
  • But this same code working into debug apk – Dhaval Jivani Jul 14 '17 at 06:47
  • Ok. may it is actually about greenrobot proguard configuration. Are you sure that you are applying those rules in you gradle file on release target? Also still check and add checks in your model.entity.Dashboard.b.a() that subscriber is not null - then it won't crash with NPE (but probably still won't work) – shtolik Jul 14 '17 at 06:53
  • @shtolik Thank you for your quick reply :) I will check and revert back to you – Dhaval Jivani Jul 14 '17 at 06:55
  • @shtolik Thank you very much -keep class model.entity.Dashboard.** { *; } this code worked for me – Dhaval Jivani Jul 14 '17 at 07:00
  • Good. I'll post it as an answer then:) – shtolik Jul 14 '17 at 07:05

1 Answers1

2

Definitely sounds like proguard related, but probably not about eventbus, but about your own model.entity.Dashboard class. May be you need to add that model.entity.Dashboard into proguard exceptions:

-keep class model.entity.Dashboard.** { *; } 
shtolik
  • 1,341
  • 22
  • 29