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.66k stars 4.66k forks source link

Hongmeng (HarmonyOS) crashes during registration #726

Open yinanwang1 opened 2 months ago

yinanwang1 commented 2 months ago

Edit: updated to translate to English, as this issue tracker is in English.

鸿蒙系统注册时崩溃 Translation: Hongmeng system crashes during registration

崩溃执行的代码为 EventBus.getDefault().register(this) 在注册的时候就崩溃了。崩溃的日志如下: Translation: The code executed by the crash is EventBus.getDefault().register(this) and it crashes when registering. The crash log is as follows:

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.window.BackEvent" on path: DexPathList[[zip file "/data/app/~~mItMJVtTKf3MFXkmzjJT5g==/com.qeebike.customer-sqio0Z6TRT4C2KWW30Nl8g==/base.apk"],nativeLibraryDirectories=[/data/app/~~mItMJVtTKf3MFXkmzjJT5g==/com.qeebike.customer-sqio0Z6TRT4C2KWW30Nl8g==/lib/arm64, /data/app/~~mItMJVtTKf3MFXkmzjJT5g==/com.qeebike.customer-sqio0Z6TRT4C2KWW30Nl8g==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/lib64/module/multimedia, /system/product/lib64]]
                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                    at java.lang.reflect.Executable.getParameterTypesInternal(Native Method) 
                    at java.lang.reflect.Method.getParameterTypes(Method.java:186) 
                    at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:173) 
                    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:150) 
                    at com.qeebike.map.ui.activity.JourneyFinishActivity.onCreate(JourneyFinishActivity.kt:102) 
                    at android.app.Activity.performCreate(Activity.java:8592) 
                    at android.app.Activity.performCreate(Activity.java:8565) 
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1344) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4756) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:5006) 
                    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:123) 
                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:3082) 
                    at android.os.Handler.dispatchMessage(Handler.java:117) 
                    at android.os.Looper.loopOnce(Looper.java:205) 
                    at android.os.Looper.loop(Looper.java:293) 
                    at android.app.ActivityThread.loopProcess(ActivityThread.java:9986) 
                    at android.app.ActivityThread.main(ActivityThread.java:9975) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1240) 
Allen-cxl commented 2 months ago

我的鸿蒙也出现了 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.window.BackEvent" on path: DexPathList 机型mate40 系统harmonyos 4.0.0

greenrobot-team commented 2 months ago

There are multiple issues about this, do none of the solutions there work?

yinanwang1 commented 2 months ago

There are multiple issues about this, do none of the solutions there work?

Thank you for your replay. YES, I don't find any solution to fix this bug in the ISSUES. THE error message is: Didn't find class "android.window.BackEvent". There is no same issues.

WHAT information about this bug do you want, I can offer?

My CODE as follow:

class JourneyFinishActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (!EventBus.getDefault().isRegistered(this) && findBackEvent()) {
            EventBus.getDefault().register(this)
        }
    }

Especially, invoke the EventBus.getDefault().register(this) in the FlutterActivity file, it crashes. I don't know the reason is caused by the flutter activity or not!

I hope this is helpful and I look forward to hearing from you.

Good luck.

greenrobot-team commented 2 months ago

Please look at the issues I have linked. They are relevant to your issue which is a ClassNotFoundException. I don't have time to summarize them all here.

mainlxl commented 1 month ago

增加一个冗余类 临时解决

Translation: Add a redundant class as a temporary solution

class _SplashFlutterActivityEventReceiver(val activity: SplashFlutterActivity) {
    fun register() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onFlutterEvent(event: FlutterSendEventBean) {
      ...
    }

    fun unRegister() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
    }
}

open class SplashFlutterActivity : FlutterBoostActivity() {
  val _eventReceiver = _SplashFlutterActivityEventReceiver(this)
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        _eventReceiver.register()
                ...
    }
 override fun onDestroy() {
        super.onDestroy()
        _eventReceiver.unRegister()
   ...
    }
rajimendiswow commented 3 weeks ago

I had the same crash in my Flutter activity and temporarily fixed it with @mainlxl 's logic. Thank you!