Search code examples
javaandroidgreenrobot-eventbusgreenrobot-eventbus-3.0

GreenRobot EventBus, ClassNotFoundException still there after using Subscriber Index


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.


Solution

  • 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