firebase / flutterfire

šŸ”„ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.65k stars 3.96k forks source link

šŸ› [firebase_messaging] (iOS) App crashes immediately on notification click (EXC_BAD_ACCESS (KERN_INVALID_ADDRESS)) #10551

Closed DeToxer closed 1 year ago

DeToxer commented 1 year ago

Bug report

Describe the bug This bug occurs when the app is terminated (not running) and i receive a push notification. The push notification is received and displayed as expected by the OS, but when i click the notification it attempts to open the app, but it immediately shuts down/crashes. I want to emphasize that this only happens on iOS and when the app is terminated. If the app is in the background and i click the notification, it resumes the app as expected.

After this has happened the app is in a broken state meaning that if i now attempt to open the app normally (clicking the launch icon), the same thing happens; the app shuts down/crashes. I have to re-install the app to make it well again. I have tested on iPhone 6s (iOS 14.7.1) and iPhone 14 Pro Max (iOS 16.3.1) and it occurs on both of them, consistently.

Below is a screen recording where I:

  1. Terminates the app which was running just fine
  2. Send a push notification to the app
  3. Clicks the notification (instant crash occurs)
  4. Click the launch icon (instant crash occurs).

https://user-images.githubusercontent.com/13535388/222383646-93161334-9543-4893-ba30-c8d03b971e7b.MP4

Stack trace:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x32ab90 swift_getObjectType + 36
1  flutter_secure_storage         0x8b40 $s22flutter_secure_storage31SwiftFlutterSecureStoragePluginC8register4withySo0eH9Registrar_p_tFZ + 108
2  flutter_secure_storage         0x8d30 $s22flutter_secure_storage31SwiftFlutterSecureStoragePluginC8register4withySo0eH9Registrar_p_tFZTo + 56
3  flutter_secure_storage         0x4e98 +[FlutterSecureStoragePlugin registerWithRegistrar:] + 72
4  Runner                         0x51c8 +[GeneratedPluginRegistrant registerWithRegistry:] + 108 (GeneratedPluginRegistrant.m:108)
5  Runner                         0x546c AppDelegate.application(_:didFinishLaunchingWithOptions:) + 10 (AppDelegate.swift:10)
6  Runner                         0x5734 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) (<compiler-generated>)
7  ???                            0x1966607b0 (Missing)
8  ???                            0x196662150 (Missing)
9  ???                            0x196667f24 (Missing)
10 ???                            0x195d3a8c0 (Missing)
11 ???                            0x19625f2c8 (Missing)
12 ???                            0x195d3b3a8 (Missing)
13 ???                            0x195d3adfc (Missing)
14 ???                            0x195d3b1d4 (Missing)
15 ???                            0x195d3aa90 (Missing)
16 ???                            0x195d4272c (Missing)
17 ???                            0x19617938c (Missing)
18 ???                            0x196277184 (Missing)
19 ???                            0x195d42420 (Missing)
20 ???                            0x195b81ae4 (Missing)
21 ???                            0x195b80590 (Missing)
22 ???                            0x195b81730 (Missing)
23 ???                            0x1966660fc (Missing)
24 ???                            0x19619fa84 (Missing)
25 ???                            0x1a2899d00 (Missing)
26 ???                            0x1a28c14fc (Missing)
27 ???                            0x1a28a7420 (Missing)
28 ???                            0x1a28c1214 (Missing)
29 ???                            0x1939f7298 (Missing)
30 ???                            0x19399c5b8 (Missing)
31 ???                            0x1a28e5e04 (Missing)
32 ???                            0x1a28e5acc (Missing)
33 ???                            0x1a28e5fa0 (Missing)
34 CoreFoundation                 0x9a8a8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
35 CoreFoundation                 0x9a7a8 __CFRunLoopDoSource0 + 204
36 CoreFoundation                 0x99afc __CFRunLoopDoSources0 + 256
37 CoreFoundation                 0x94018 __CFRunLoopRun + 768
38 CoreFoundation                 0x937d0 CFRunLoopRunSpecific + 572
39 ???                            0x1aa479570 (Missing)
40 ???                            0x1966642d0 (Missing)
41 ???                            0x19666984c (Missing)
42 Runner                         0x58ac main + 5 (AppDelegate.swift:5)
43 ???                            0x193a16140 (Missing)

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a Flutter plugin project
  2. Follow this installation guide in order to set up Firebase cloud messaging so that it is ready for receiving notifications.
  3. Fire up the application and copy the FCM token (FirebaseMessaging.instance.getToken())
  4. After you have obtained the token, terminate the app (kill it).
  5. Now, open the Firebase console and navigate to the "Cloud Messaging" category and send a test message to the device using the FCM registration token you just copied.
  6. When the app has received the push notification, click it
  7. Observe the app crashes immediately when clicking the notification

Expected behavior

When the app is in terminated state and i receive a push notification, when i click the notification i expect the app to open

Sample project

Providing a minimal example project which demonstrates the bug in isolation from your main App greatly enhances the chance of a timely fix. Please link to the public repository URL.

A bit difficult to provide a working project that supports Firebase messaging


Additional context

When looking at the stack trace you might think that the package flutter_secure_storage is to blame but I have tried removing the package and the crash still occurs with a slightly different stack trace.

Again, this is a Flutter plugin project. I am running the example app within the project.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [āœ“] Flutter (Channel stable, 3.7.6, on macOS 13.2.1 22D68 darwin-arm64, locale nb-NO) ā€¢ Flutter version 3.7.6 on channel stable at /Users/detoxer/dev/sdk/flutter ā€¢ Upstream repository https://github.com/flutter/flutter.git ā€¢ Framework revision 12cb4eb7a0 (14 hours ago), 2023-03-01 10:29:26 -0800 ā€¢ Engine revision ada363ee93 ā€¢ Dart version 2.19.3 ā€¢ DevTools version 2.20.1 [āœ“] Android toolchain - develop for Android devices (Android SDK version 32.0.0) ā€¢ Android SDK at /Users/detoxer/Library/Android/sdk ā€¢ Platform android-33, build-tools 32.0.0 ā€¢ Java binary at: /Users/detoxer/dev/ide/Android Studio.app/Contents/jbr/Contents/Home/bin/java ā€¢ Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) ā€¢ All Android licenses accepted. [āœ“] Xcode - develop for iOS and macOS (Xcode 14.2) ā€¢ Xcode at /Applications/Xcode.app/Contents/Developer ā€¢ Build 14C18 ā€¢ CocoaPods version 1.11.2 [āœ“] Chrome - develop for the web ā€¢ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [āœ“] Android Studio (version 2022.1) ā€¢ Android Studio at /Users/detoxer/dev/ide/Android Studio.app/Contents ā€¢ Flutter plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/9212-flutter ā€¢ Dart plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/6351-dart ā€¢ Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) [āœ“] VS Code (version 1.73.1) ā€¢ VS Code at /Users/detoxer/dev/ide/Visual Studio Code.app/Contents ā€¢ Flutter extension can be installed from: šŸ”Ø https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [āœ“] Connected device (4 available) ā€¢ Smartly's iPhone (mobile) ā€¢ c6684fab9044c7008a2dc189294953a7a06d0509 ā€¢ ios ā€¢ iOS 14.7.1 18G82 ā€¢ iPhone 14 Pro (mobile) ā€¢ 8BFD8725-EF0B-4B05-97EC-7C810DCD7B6A ā€¢ ios ā€¢ com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator) ā€¢ macOS (desktop) ā€¢ macos ā€¢ darwin-arm64 ā€¢ macOS 13.2.1 22D68 darwin-arm64 ā€¢ Chrome (web) ā€¢ chrome ā€¢ web-javascript ā€¢ Google Chrome 110.0.5481.177 [āœ“] HTTP Host Availability ā€¢ All required HTTP hosts are available ā€¢ No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.19.3 Flutter SDK 3.7.6 lyselib 0.0.1 dependencies: - animated_toggle_switch 0.6.1 [flutter] - cupertino_icons 1.0.5 - custom_sliding_segmented_control 1.7.4 [flutter] - device_info_plus 8.1.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32] - dio 5.0.1 [http_parser meta path] - dots_indicator 2.1.0 [flutter] - firebase_analytics 10.1.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.7.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.0.15 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 14.2.5 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_animate 4.1.0 [flutter] - flutter_bloc 8.1.2 [flutter bloc provider] - flutter_html 3.0.0-alpha.6 [html csslib collection numerus flutter] - flutter_local_notifications 13.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_secure_storage 8.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_svg 2.0.2 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - google_api_availability 3.0.1 [flutter meta] - intl 0.17.0 [clock path] - lottie 2.2.0 [archive flutter path vector_math] - package_info_plus 3.0.3 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - path_provider 2.0.13 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - pull_to_refresh_flutter3 2.0.1 [flutter] - rxdart 0.27.7 - share_plus 6.3.1 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - shared_preferences 2.0.18 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shimmer 2.0.0 [flutter] - syncfusion_flutter_charts 20.4.52 [flutter intl vector_math syncfusion_flutter_core] - syncfusion_flutter_gauges 20.4.52 [flutter syncfusion_flutter_core intl] - syncfusion_flutter_pdfviewer 20.4.52 [flutter vector_math async http uuid intl syncfusion_pdfviewer_platform_interface syncfusion_pdfviewer_web syncfusion_pdfviewer_macos syncfusion_pdfviewer_windows syncfusion_flutter_core syncfusion_flutter_pdf url_launcher] - synchronized 3.0.1 - transparent_image 2.0.1 - url_launcher 6.1.10 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - web_socket_channel 2.3.0 [async crypto stream_channel] - webview_flutter 4.0.5 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] dev dependencies: - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] transitive dependencies: - _flutterfire_internals 1.0.16 [collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.3.6 [crypto path pointycastle] - args 2.4.0 - async 2.10.0 [collection meta] - bloc 8.1.1 [meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.2.1 - clock 1.1.1 - collection 1.17.0 - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.2 [typed_data] - csslib 0.17.2 [source_span] - dbus 0.7.8 [args ffi meta xml] - device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.21 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+12 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.2.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.3.15 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.14 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.15 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - flutter_local_notifications_linux 3.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_linux 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 3.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 2.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - html 0.15.1 [csslib source_span] - http 0.13.5 [async http_parser meta path] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - js 0.6.5 [meta] - lints 2.0.1 - matcher 0.12.13 [meta stack_trace] - material_color_utilities 0.2.0 - meta 1.8.0 - mime 1.0.4 - nested 1.0.0 [flutter] - numerus 2.0.0 [characters] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.0.23 [flutter path_provider_platform_interface] - path_provider_foundation 2.1.2 [flutter path_provider_platform_interface] - path_provider_linux 2.1.9 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.4 [ffi flutter path path_provider_platform_interface win32] - petitparser 5.1.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.4 [meta] - pointycastle 3.6.2 [collection convert js] - process 4.2.4 [file path platform] - provider 6.0.5 [collection flutter nested] - share_plus_platform_interface 3.2.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shared_preferences_android 2.0.16 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.1.4 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.4 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.1.1 [flutter plugin_platform_interface] - shared_preferences_web 2.0.5 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.4 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.9.1 [collection path term_glyph] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - syncfusion_flutter_core 20.4.52 [vector_math flutter] - syncfusion_flutter_pdf 20.4.52 [flutter intl xml syncfusion_flutter_core crypto convert] - syncfusion_pdfviewer_macos 20.4.52 [flutter syncfusion_pdfviewer_platform_interface] - syncfusion_pdfviewer_platform_interface 20.4.52 [flutter plugin_platform_interface] - syncfusion_pdfviewer_web 20.4.52 [flutter flutter_web_plugins js meta syncfusion_pdfviewer_platform_interface] - syncfusion_pdfviewer_windows 20.4.52 [flutter] - term_glyph 1.2.1 - test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.9.1 [path] - typed_data 1.3.1 [collection] - url_launcher_android 6.0.24 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.1 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.15 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.4 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_graphics 1.1.0 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.0 - vector_graphics_compiler 1.1.0 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - webview_flutter_android 3.3.1 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 2.0.2 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 3.1.1 [flutter path webview_flutter_platform_interface] - win32 3.1.3 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.2.2 [co ```

darshankawar commented 1 year ago

Thanks for the report @DeToxer

1 flutter_secure_storage 0x8b40 $s22flutter_secure_storage31SwiftFlutterSecureStoragePluginC8register4withySo0eH9Registrar_p_tFZ + 108 2 flutter_secure_storage 0x8d30 $s22flutter_secure_storage31SwiftFlutterSecureStoragePluginC8register4withySo0eH9Registrar_p_tFZTo + 56 3 flutter_secure_storage 0x4e98 +[FlutterSecureStoragePlugin registerWithRegistrar:] + 72

This as you mentioned points to third party package.

and the crash still occurs with a slightly different stack trace.

Can you provide the stacktrace ?

2. Follow this installation guide in order to set up Firebase cloud messaging so that it is ready for receiving notifications.

This link is archived and no more updated. The new home for flutterfire plugins is https://firebase.google.com/docs/flutter/setup?platform=ios, so please try to follow the instructions as mentioned here to add firebase_messaging on iOS and see if using it, you still get the same crash or not.

DeToxer commented 1 year ago

Can you provide the stacktrace ?

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
Crashed: com.apple.main-thread
0  ???                            0x197a51b90 (Missing)
1  ???                            0x105340b40 (Missing)
2  ???                            0x105340b40 (Missing)
3  ???                            0x105340d30 (Missing)
4  ???                            0x10533ce98 (Missing)
5  Runner                         0x51c8 +[GeneratedPluginRegistrant registerWithRegistry:] + 108 (GeneratedPluginRegistrant.m:108)
6  Runner                         0x546c AppDelegate.application(_:didFinishLaunchingWithOptions:) + 10 (AppDelegate.swift:10)
7  Runner                         0x5734 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) (<compiler-generated>)
8  ???                            0x1966607b0 (Missing)
9  ???                            0x196662150 (Missing)
10 ???                            0x196667f24 (Missing)
11 ???                            0x195d3a8c0 (Missing)
12 ???                            0x19625f2c8 (Missing)
13 ???                            0x195d3b3a8 (Missing)
14 ???                            0x195d3adfc (Missing)
15 ???                            0x195d3b1d4 (Missing)
16 ???                            0x195d3aa90 (Missing)
17 ???                            0x195d4272c (Missing)
18 ???                            0x19617938c (Missing)
19 ???                            0x196277184 (Missing)
20 ???                            0x195d42420 (Missing)
21 ???                            0x195b81ae4 (Missing)
22 ???                            0x195b80590 (Missing)
23 ???                            0x195b81730 (Missing)
24 ???                            0x1966660fc (Missing)
25 ???                            0x19619fa84 (Missing)
26 ???                            0x1a2899d00 (Missing)
27 ???                            0x1a28c14fc (Missing)
28 ???                            0x1a28a7420 (Missing)
29 ???                            0x1a28c1214 (Missing)
30 ???                            0x1939f7298 (Missing)
31 ???                            0x19399c5b8 (Missing)
32 ???                            0x1a28e5e04 (Missing)
33 ???                            0x1a28e5acc (Missing)
34 ???                            0x1a28e5fa0 (Missing)
35 ???                            0x193d3e8a8 (Missing)
36 ???                            0x193d3e7a8 (Missing)
37 ???                            0x193d3dafc (Missing)
38 ???                            0x193d38018 (Missing)
39 ???                            0x193d377d0 (Missing)
40 ???                            0x1aa479570 (Missing)
41 ???                            0x1966642d0 (Missing)
42 ???                            0x19666984c (Missing)
43 Runner                         0x58ac main + 5 (AppDelegate.swift:5)
44 ???                            0x193a16140 (Missing)

This link is archived and no more updated. The new home for flutterfire plugins is https://firebase.google.com/docs/flutter/setup?platform=ios, so please try to follow the instructions as mentioned here to add firebase_messaging on iOS and see if using it, you still get the same crash or not.

I followed the instructions -> same outcome unfortunately

DeToxer commented 1 year ago

@darshankawar I've had a development in this case. Turns out the crash is due to something completely different. I'm installing the app on a physical device which works fine. When i terminate the app and click the launcher icon, the same thing happens -> crash. This happens regardless for weather or not firebase packages are added to the app or not. I literally removed all third party packages and most of the source code and fired up the app (which was just a Text widget saying "Hello world" wrapped in a MeterialApp-widget) and the same thing happened -> exact same crash.

I guess it has something to do with how debug builds are installed on physical devices via Android Studio or something.

darshankawar commented 1 year ago

alright thanks for this update. That means the issue is not specific to messaging plugin. I wa actually trying to replicate the reported behavior using messaging plugin example on iPhone 6s device. Terminated the app and then sent a notification, tapped on it which leads to lost connection to device. But after going through documentation, it states that when we are terminating the app by swiping it away, we need to manually reopen it:

https://firebase.google.com/docs/cloud-messaging/flutter/receive

Based on your feedback, I'll go ahead and close it as not a plugin issue. If you disagree, write in comments and I'll reopen it.