HMS-Core / hms-flutter-plugin

This repo contains all of Flutter HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
285 stars 142 forks source link

Crash when registering background push message handler #317

Open bkleineibst opened 1 year ago

bkleineibst commented 1 year ago

I am seeing the following crash on some devices when registering a background push handler:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, java.lang.Integer cannot be cast to java.lang.Long, null, java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
    at com.huawei.hms.flutter.push.PushPlugin.registerBackgroundMessageHandler(PushPlugin.java:369)
    at com.huawei.hms.flutter.push.PushPlugin.onMethodCall(PushPlugin.java:170)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8349)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
)

This doesn't happen on cloud debugging and only seems to affect less than 5% of users.

I am trying the following change to line 369 of PushPlugin.java to see if that resolves it: Change

long userCallbackHandle = Objects.requireNonNull(call.argument("rawCallback"));

to

long userCallbackHandle = ((Number) Objects.requireNonNull(call.argument("rawCallback"))).longValue(); 
Matthewloughton commented 8 months ago

I'm also having this issue on a Y5 lite. The Y5 lite has access to google play services, but I'm testing both on the device

qwertyway commented 5 months ago

Same problem here. Latest library version huawei_push: 6.12.0+300