ably / ably-flutter

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.
https://ably.com/download
Apache License 2.0
60 stars 16 forks source link

Android application got crash on notification receive in killed state using Ably notifications #437

Open Asharulislam opened 2 years ago

Asharulislam commented 2 years ago

Now I am using latest package of Ably 1.2.15. Flutter version 2.5.3

Reference to ISSUE : https://github.com/ably/ably-flutter/issues/429

QuintinWillison ikbalkaya

If I send notifications then in Android (in terminated state) Application got crash.

Steps to reproduce:

1) Fire 6 to 8 notifications when the app is killed. 2) Received 2 or 4 notifications and some are still pending. 3) Just open the App (not from tapping the notification) from apps menu. 4) App just got crashed.

Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: io.ably.flutter.plugin. Response ID: 0 W/FlutterJNI(13840): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: io.ably.flutter.plugin. Response ID: 0 E/AndroidRuntime(13840): FATAL EXCEPTION: main E/AndroidRuntime(13840): Process: com.appiskey.dang.dev, PID: 13840 E/AndroidRuntime(13840): java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(13840): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:164) E/AndroidRuntime(13840): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238) E/AndroidRuntime(13840): at io.ably.flutter.plugin.AblyMethodCallHandler$MethodResultWrapper.lambda$success$0$AblyMethodCallHandler$MethodResultWrapper(AblyMethodCallHandler.java:133) E/AndroidRuntime(13840): at io.ably.flutter.plugin.-$$Lambda$AblyMethodCallHandler$MethodResultWrapper$mM2gyGmNB_FxOxEa-tdyQn04YRo.run(Unknown Source:4) E/AndroidRuntime(13840): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(13840): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(13840): at android.os.Looper.loop(Looper.java:246) E/AndroidRuntime(13840): at android.app.ActivityThread.main(ActivityThread.java:8506) E/AndroidRuntime(13840): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(13840): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) E/AndroidRuntime(13840): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

h3. Some Time this error occured: FATAL EXCEPTION: main E/AndroidRuntime(18800): Process: com.appiskey.dang.dev, PID: 18800 E/AndroidRuntime(18800): java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(18800): at io.flutter.embedding.engine.o.e.a(Unknown Source:35) E/AndroidRuntime(18800): at g.b.d.a.v.b(Unknown Source:14) E/AndroidRuntime(18800): at g.a.a.a.k1.e(:1) E/AndroidRuntime(18800): at g.a.a.a.p0.run(Unknown Source:4) E/AndroidRuntime(18800): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(18800): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(18800): at android.os.Looper.loop(Looper.java:246) E/AndroidRuntime(18800): at android.app.ActivityThread.main(ActivityThread.java:8506) E/AndroidRuntime(18800): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(18800): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) E/AndroidRuntime(18800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

┆Issue is synchronized with this Jira Bug by Unito

ikbalkaya commented 2 years ago

Thanks for reporting this @Asharulislam. Can you please confirm that you had this issue since v1.2.15?

Asharulislam commented 2 years ago

@ikbalkaya Yes the above issue is occurred when I am using v1.2.15.

ikbalkaya commented 2 years ago

Thank you. I will investigate

JakubJankowski commented 1 year ago

A small update from me - I've looked into it today for a bit, but couldn't find a way to reproduce this crash (tried using the example app with various emulators and a physical device, hasn't crashed once).

I'm leaving Ably, so for whomever looks at it in the future - since it seems like this started happening since v. 1.2.15, it might be connected to the ably-java version bump (unlikely): https://github.com/ably/ably-flutter/pull/435 Or more likely - to using the main thread to send messages to Flutter plugin, which might cause ANRs again: https://github.com/ably/ably-flutter/pull/431/files

Please keep in mind that all those issues might become irrelevant once we switch to the federated plugin approach, but that will probably take a while.

deanna-lad commented 1 year ago

The corresponding Jira issue is https://ably.atlassian.net/browse/SDK-2480

ikbalkaya commented 1 year ago

@Asharulislam Could you provide Android version that causes this issue please? For the note I tested this on Android 11 and 13. It turns out that

Asharulislam commented 1 year ago

@ikbalkaya My android version was 12.

Ably version 1.2.15. Flutter version 2.5.3

ikbalkaya commented 1 year ago

Thanks @Asharulislam. I just did another test with

The behaviour was similar to the one as Android 11. Notifications aren't received but I did not experience a crash on app startup. When I was doing initial testing I realized the Flutter version was 2.8.0 - Would it be possible for you to increase your Flutter version and give it another go and see whether you are having a similar issue. In the meantime I realize that not receiving push messages when the app is terminated is another issue and I'm going to look into addressing it.

Also please could you try using a release build of your app when testing push notifications on terminated state?

YumengNevix commented 1 year ago

if you open "Auto start" setting, you will receive message even if app is closed. Howerer, ably will start a new flutter engine to transport message to flutter. I think it's useless. To fix this problem , you can remove default FIrebaseMessageReceiver and remove ManuFlutterXXXX invoke.