greenrobot / EventBus

Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
http://greenrobot.org/eventbus/
Apache License 2.0
24.68k stars 4.66k forks source link

Crash when register a AppCompatTextView sub class caused by java.lang.NoClassDefFoundError #663

Closed jiulongw closed 3 years ago

jiulongw commented 3 years ago

Similar with #608 but: 1) still happens in latest version 3.2.0 2) only happens when R8 minify is enabled

So it seems like the patch for #608 did not cover all possible code paths.

I created repo eventbus-issue-repro with an empty Android app for you to try it out. This particular commit triggers the crash.

Create a release build and install it on an API-25 device. You should see following crash stack:

03-17 12:32:08.191  9065  9065 E AndroidRuntime: java.lang.NoClassDefFoundError: android.view.textclassifier.TextClassifier
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.Class.getDexCacheType(Class.java:2551)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.reflect.Method.getParameterTypes(Method.java:193)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at d.a.a.p.a()
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at com.example.eventbusbug.TestTextView.onAttachedToWindow(:7)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.View.dispatchAttachedToWindow(View.java:15509)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1526)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.Choreographer.doCallbacks(Choreographer.java:686)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.Choreographer.doFrame(Choreographer.java:621)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:751)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:95)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6119)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
03-17 12:32:08.191  9065  9065 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.textclassifier.TextClassifier" on path: DexPathList[[zip file "/data/app/com.example.eventbusbug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.eventbusbug-1/lib/x86, /system/lib, /vendor/lib]]
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
03-17 12:32:08.191  9065  9065 E AndroidRuntime:    ... 26 more
03-17 12:32:08.222  1689  3609 W ActivityManager:   Force finishing activity com.example.eventbusbug/.MainActivity
greenrobot-team commented 3 years ago

If this only happens after turning on ProGuard I guess you should check your rules. As a first step, try the rules suggested in the README: https://github.com/greenrobot/EventBus#r8-proguard

jiulongw commented 3 years ago

Thanks. In the real project we do add proguard rules for EventBus but I guess it was from a previous version. After updating to latest version of proguard rules this is fixed.