3

I have the common "ClassNotFoundException" issue EventBus with a 4.4.2 device, It's even troubleshot in the FAQ

I first double checked that I didn't use any unapropriated lifecycle methods but I didn't. Then I updated to EventBus 3.0.0, and used "suscribers index". But the bug is still here and I still can see in my stacktrace that the builder is trying to use reflexivity (findUsingReflectionInSingleClass):

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.os.PersistableBundle" on path: DexPathList[[zip file "/data/app/com.m360.android.debug-6.apk"],nativeLibraryDirectories=[/data/app-lib/com.m360.android.debug-6, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at java.lang.Class.getDeclaredMethods(Native Method) 
    at java.lang.Class.getPublicMethodsRecursive(Class.java:894) 
    at java.lang.Class.getMethods(Class.java:877) 
    at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:157) 
    at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88) 
    at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64) 
    at org.greenrobot.eventbus.EventBus.register(EventBus.java:136) 
    at com.m360.android.activity.PlayerActivity.onStart(PlayerActivity.java:977) 
    at ... 

In Player Activity :

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(QuestionFragment.EnableNextEvent event) {

    /* ...... */

}

@Override
protected void onStart() {
    super.onStart();
    EventBus.builder().addIndex(new MyEventBusIndex()).build().register(this);
}

@Override
protected void onStop() {
    super.onStop();
    EventBus.getDefault().unregister(this);
}

Also MyEventBusIndex is available so i guess my build files are fine.

Please let me know if you see what's the problem.

Renaud Favier
  • 1,645
  • 1
  • 17
  • 33
  • 1
    Are you sure you are not overriding the onCreate (Bundle savedInstanceState, PersistableBundle persistentState) method in your Activity? It sounds like even just overriding it (not only calling "subscribe" within it) can cause this crash. – Brett Jul 15 '16 at 10:25
  • 1
    I double checked like I said, and since you raised a doubt I checked again. Found it in a parent of all my activities... It works fine now thanks a lot ! – Renaud Favier Jul 15 '16 at 10:31
  • 1
    That's how it goes sometimes :) Cheers. – Brett Jul 15 '16 at 10:48
  • 1
    Glad you got it solved. To provide some background on why this happened with the subscriber index: findUsingReflectionInSingleClass is only called if the subscriber class is absent in the index. The question would be why... – Markus Junginger Jul 15 '16 at 11:33
  • yes, but now that I don't have a crash anymore, I don't know if the index is used or just if reflexion works. – Renaud Favier Jul 15 '16 at 12:31

1 Answers1

3

I had the same error on Galaxy s3 (android 4.3). It happens on Android where API level is below 21 and you have the direct reference to PersistableBundle.

"EventBus 3 with a subscriber index" didn't help to me (as and to you). So the workaround I found here.

A bit more of the error/cause is here.

P.S. eventbus 3.0.0