Eventbus: App crashes when using WebChromeClient.FileChooserParams with EventBus on Pre-Lollipop devices

Created on 24 Mar 2017  路  9Comments  路  Source: greenrobot/EventBus

App keeps crashing while registering EventBus on Pre-Lollipop devices while using WebChromeClient.FileChooserParams

Below is the stack-trace

Stacktrace: android / webkit / WebChromeClient$FileChooserParams

java.lang.Class.getDeclaredMethods(Native Method)
java.lang.Class.getPublicMethodsRecursive(Class.java: 955)
java.lang.Class.getMethods(Class.java: 938)
org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java: 157)
org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java: 88)
org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java: 64)
org.greenrobot.eventbus.EventBus.register(EventBus.java: 136)
com.semaphore.common.CommonActivity.onResume(CommonActivity.java: 138)
com.semaphore.login.WebViewerActivity.onResume(WebViewerActivity.java: 629)
android.app.Instrumentation.callActivityOnResume(Instrumentation.java: 1184)
android.app.Activity.performResume(Activity.java: 5082)
android.app.ActivityThread.performResumeActivity(ActivityThread.java: 2565)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java: 2603)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2089)
android.app.ActivityThread.access$600(ActivityThread.java: 130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1195)
android.os.Handler.dispatchMessage(Handler.java: 99)
android.os.Looper.loop(Looper.java: 137)
android.app.ActivityThread.main(ActivityThread.java: 4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java: 511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 553)
dalvik.system.NativeStart.main(Native Method)::Cause: java.lang.ClassNotFoundException: android.webkit.WebChromeClient$FileChooserParams
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java: 61)
java.lang.ClassLoader.loadClass(ClassLoader.java: 501)
java.lang.ClassLoader.loadClass(ClassLoader.java: 461)
java.lang.Class.getDeclaredMethods(Native Method)
java.lang.Class.getPublicMethodsRecursive(Class.java: 955)

If anyone faced similar previously can provide a solution

Most helpful comment

@lalit3686 EventBus uses reflection to find the Subscriber annotations on whatever you are registering. As part of loading that class (or one of its dependencies) the classloader attempts to load WebChromeClient$FileChooserParams.

All 9 comments

There is your issue: dalvik.system.NativeStart.main(Native Method)::Cause: java.lang.ClassNotFoundException: android.webkit.WebChromeClient$FileChooserParams

Looking at the docs, WebChromeClient.FileChooserParams was added in API level 21. It is not available on "pre-Lollipop" devices.
-ut

Yes, but still is there anyway that it should not crash on pre-lollipop devices? Because atleast app should crash, right?

@lalit3686 your app is referencing android.webkit.WebChromeClient$FileChooseParams. You need to remove this reference from your app if you expect it to run on pre-lollipop devices.

This has nothing to do with EventBus.

This has to do with EventBus for sure, because I tried removing EventBus and then there was no problem at all!

@lalit3686 that just means that the code that is loading WebChromeClient$FileChoosrParams isn't being invoked when you removed EventBus. So you are no longer exercising all of your app.

EventBus has zero dependencies on WebChromeClient.
Buty don't take my word for it. Look yourself.

@william-ferguson-au as you can see in the crash report the crash is being generated by register method of EventBus. So, if I just remove that part of registering EventBus then it works fine, how?

@lalit3686 EventBus uses reflection to find the Subscriber annotations on whatever you are registering. As part of loading that class (or one of its dependencies) the classloader attempts to load WebChromeClient$FileChooserParams.

Is there anyway I can handle this scenario of classes available for higher version can be ignored by EventBus while registering & performing reflection?

Thanks @william-ferguson-au for the explanations!

@lalit3686 what @william-ferguson-au said. Also you might want to look at how to make your Android app compatible with all versions of Android. (edit: specifically the _Platform version_ section)

Closing this then. -ut

Was this page helpful?
0 / 5 - 0 ratings