Skip to content
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

Hongmeng (HarmonyOS) crashes during registration #726

Open
yinanwang1 opened this issue Jun 7, 2024 · 8 comments
Open

Hongmeng (HarmonyOS) crashes during registration #726

yinanwang1 opened this issue Jun 7, 2024 · 8 comments
Labels
more info required Needs more info to become actionable.

Comments

@yinanwang1
Copy link

yinanwang1 commented Jun 7, 2024

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
Copy link

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

@greenrobot-team greenrobot-team changed the title 鸿蒙系统注册时崩溃 Hongmeng system crashes during registration Jun 10, 2024
@greenrobot-team
Copy link
Collaborator

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

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. label Jun 10, 2024
@yinanwang1
Copy link
Author

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
Copy link
Collaborator

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
Copy link

mainlxl commented Jul 3, 2024

增加一个冗余类 临时解决

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
Copy link

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

@greenrobot-team greenrobot-team changed the title Hongmeng system crashes during registration Hongmeng (HarmonyOS) crashes during registration Jul 31, 2024
@gaozhong97
Copy link

gaozhong97 commented Sep 25, 2024

    private void findUsingReflectionInSingleClass(FindState findState) {
        Method[] methods;
        try {
            // This is faster than getMethods, especially when subscribers are fat classes like Activities
            methods = findState.clazz.getDeclaredMethods();
        } catch (Throwable th) {
            // Workaround for java.lang.NoClassDefFoundError, see https://github.com/greenrobot/EventBus/issues/149
            try {
                methods = findState.clazz.getMethods();
            } catch (LinkageError error) { // super class of NoClassDefFoundError to be a bit more broad...
                String msg = "Could not inspect methods of " + findState.clazz.getName();
                if (ignoreGeneratedIndex) {
                    msg += ". Please consider using EventBus annotation processor to avoid reflection.";
                } else {
                    msg += ". Please make this class visible to EventBus annotation processor to avoid reflection.";
                }
                throw new EventBusException(msg, error);
            }
            findState.skipSuperClasses = true;
        }
        for (Method method : methods) {
            int modifiers = method.getModifiers();
            if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length == 1) {
                    Subscribe subscribeAnnotation = method.getAnnotation(Subscribe.class);
                    if (subscribeAnnotation != null) {
                        Class<?> eventType = parameterTypes[0];
                        if (findState.checkAdd(method, eventType)) {
                            ThreadMode threadMode = subscribeAnnotation.threadMode();
                            findState.subscriberMethods.add(new SubscriberMethod(method, eventType, threadMode,
                                    subscribeAnnotation.priority(), subscribeAnnotation.sticky()));
                        }
                    }
                } else if (strictMethodVerification && method.isAnnotationPresent(Subscribe.class)) {
                    String methodName = method.getDeclaringClass().getName() + "." + method.getName();
                    throw new EventBusException("@Subscribe method " + methodName +
                            "must have exactly 1 parameter but has " + parameterTypes.length);
                }
            } else if (strictMethodVerification && method.isAnnotationPresent(Subscribe.class)) {
                String methodName = method.getDeclaringClass().getName() + "." + method.getName();
                throw new EventBusException(methodName +
                        " is a illegal @Subscribe method: must be public, non-static, and non-abstract");
            }
        }
    }  

methods里面有个是空的报错 在flutterActivity内用EventBus

Translation: There is an empty error in methods. Use EventBus in flutterActivity.

@AdminQQZ
Copy link

this android lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info required Needs more info to become actionable.
Projects
None yet
Development

No branches or pull requests

7 participants