New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal Exception: java.lang.NoClassDefFoundError android/telephony/CellInfoGsm #149
Comments
Same here, I get the exception:
on specific mobile devices |
This looks like some kind of Android bug. If you have time and know how to do it, you could test if that occurs with the annotations branch. This code is not present anymore here. |
It is an issue with reflection in Event Bus, because of proguard Event Bus Solution that worked for me - Only required if you use AsyncExecutor-keepclassmembers class * extends add this to proguard-project.txt Pankaj On Wed, Feb 25, 2015 at 1:32 PM, greenrobot notifications@github.com
|
So, this can be closed? |
I'm seeing this issue too. I did a little digging into the code and found the issue. It does seem to be an Android quirk (specifically in java.lang.Class), but I think it was introduced into EventBus at e47442b.
See lines 763, 770, and 822 in https://android.googlesource.com/platform/libcore/+/a8a489492749b845cc2a85d67c664449d7b0b019/libart/src/main/java/java/lang/Class.java.
|
Yes that is correct. Pankaj On Fri, Feb 27, 2015 at 7:21 AM, Dan Huang notifications@github.com wrote:
|
Thanks for investigating. getMethods is much slower than getDeclaredMethods. Maybe in combination with try/catch... |
You only need to call getMethods once, not for each superclass, so it might On Fri, Feb 27, 2015 at 12:09 AM, greenrobot notifications@github.com
|
- Refactor ImageWorker to provide additional loadImage(...) methods that can: - load an image, and then call a callback - load an image in to a RemoteViews, and post a notification - Use these new methods in updateOngoingNotification() to load the images in to the notification's view and post the new notification. This causes a problem with EventBus on pre-Lollipop devices, as it uses Class#getDeclaredMethods() finds methods that do not exist or have non-existent return types on earlier devices. Guarding the code with @TargetApi or checks against Build.VERSION.SDK_INT does not solve this problem. This is discussed in issues on EventBus, such as greenrobot/EventBus#149 (comment). The fork of EventBus at https://github.com/yuzeh/EventBus fixes this, per the pull request at greenrobot/EventBus#158 and yuzeh/EventBus@dc326b0 so for the moment pull that code in as a submodule and use it in preference to the official EventBus code.
Could someone confirm that be04a2d fixed the issue? Will do a 2.4.1 release once confirmed. |
@yuzeh Thanks so much for investigating! Decided to do it as plan B only, because it's not so common and getDeclaredMethods is much faster last time I checked. |
removed onRestoreInstanceState from my activity and problem solved |
I am still seeing this in EventBus 3.0.0 when a class I'm using EventBus in has some method which references a higher API than the device I am running on. Please see this tiny sample project: Which crashes on launch:
This crash is seen when running on a 4.4.2 emulator. |
@greenrobot can we re-open this? |
@skyler-b are you using an index for eventbus 3? it might help to work around this because it avoids reflection. |
I hadn't heard of the subscriber index, but yes, after adding it to my project the crash does go away. Great work around, thanks for the tip! |
@skyler-b great. If it's reproducible for you without the index, would you be available to pinpoint the issue, so we can add a FAQ entry? In #182 it was suggested to remove Activity#onSaveInstanceState(Bundle, PersistableBundle) in favor of Activity#onSaveInstanceState(Bundle). Which is the subscriber class that is triggering the issue for you? Did you override any methods having a PermissionRequest param? PermissionRequest is API level 21 - what does the affected device have? |
@greenrobot if you refer to the gist I posted (https://gist.github.com/skyler-b/2bfea0b0bbb4ebdb5080), it pinpoints the issue pretty concisely. The crash posted occurs on a 4.4.2 emulator. |
@skyler-b Does it help to make the "offending" method private? |
@greenrobot Yes - a private method with an advanced API does not cause a crash. For example, in my sample project, making |
Awesome! I added a rather long FAQ entry for this: http://greenrobot.org/eventbus/documentation/faq/ Thanks for your help! |
Document looks great, thanks for the explanation! |
getMethods also occur NoClassDefFoundError on some devices,maybe add catch around getMethods Method[] methods;
try {
// This is faster than getMethods, especially when subscribers are fat classes like Activities
methods = findState.clazz.getDeclaredMethods();
} catch (Throwable th) {
try {
methods = findState.clazz.getMethods();
}catch (Throwable th2){
return;
}finally {
findState.skipSuperClasses = true;
}
} |
Hi,
On specific mobiles eventbus crashes with following error.
Fatal Exception: java.lang.NoClassDefFoundError
android/telephony/CellInfoGsm
de.greenrobot.event.SubscriberMethodFinder.findSubscriberMethods
Caused by java.lang.ClassNotFoundException
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:61)
java.lang.Class.getDeclaredMethods (Class.java:703)
de.greenrobot.event.SubscriberMethodFinder.findSubscriberMethods (SubscriberMethodFinder.java:75)
de.greenrobot.event.EventBus.register (EventBus.java:163)
de.greenrobot.event.EventBus.registerSticky (EventBus.java:151)
Looks like findSubscriberMethods is trying to access methods which are marked as @TargetApi(17) while the phone is using api 16. Hence eventbus is not able to find those classes which are not available in api 16. Looks like a bug. Is there any workaround?
The text was updated successfully, but these errors were encountered: