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.56k stars 3.93k forks source link

🐛 [firebase_core] Debug connection gets lost #11684

Closed milindgoel15 closed 9 months ago

milindgoel15 commented 10 months ago

Bug report

Describe the bug After upgrading firebase plugins to their major versions, they make the app non-debuggable on windows by terminating the connection before the app even shows up:

√  Built build\windows\runner\Debug\weatherwise.exe.
Connecting to VM Service at ws://127.0.0.1:56889/qMd2bgffUi4=/ws
Lost connection to device.
Exited (sigterm)

An older version before the upgrade works fine btw. these versions below:

  firebase_analytics 10.4.5 (10.5.1 available)
  firebase_analytics_platform_interface 3.6.5 (3.7.1 available)
  firebase_analytics_web 0.5.4+5 (0.5.5+1 available)
  firebase_core 2.15.1 (2.17.0 available)
  firebase_core_web 2.7.0 (2.8.0 available)
  firebase_performance 0.9.2+5 (0.9.2+7 available)
  firebase_performance_platform_interface 0.1.4+5 (0.1.4+7 available)
  firebase_performance_web 0.1.4+5 (0.1.4+7 available)

Steps to reproduce

Steps to reproduce the behavior:

  1. Use latest versions of firebase core, analytics, performance
  2. 'generate firebase project
  3. start windows debugger
  4. throws connection lost

Expected behavior

Works

Sample project

reproducible steps: https://github.com/firebase/flutterfire/issues/11684#issuecomment-1772490113


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` @Milind ➜ ~ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.6, on Microsoft Windows [Version 10.0.22621.2361], locale en-IN) [✓] Windows Version (Installed version of Windows is version 10 or higher) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.0) [✓] Android Studio (version 2022.3) [✓] VS Code, 64-bit edition (version 1.83.0) [✓] Connected device (1 available) [✓] Network resources • No issues found! ```

Flutter dependencies

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

Click To Expand ``` @Milind ➜ weatherwise git(main) flutter pub deps -- --style=compact Dart SDK 3.1.3 Flutter SDK 3.13.6 weatherwise 2.3.3+233 dependencies: - animate_do 3.1.2 [flutter] - animations 2.0.8 [flutter] - cached_network_image 3.3.0 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image] - device_info_plus 10.0.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32 win32_registry] - dynamic_color 1.6.7 [flutter flutter_test material_color_utilities] - firebase_analytics 10.5.1 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.17.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_performance 0.9.2+7 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter] - fl_chart 0.64.0 [equatable flutter] - flex_color_picker 3.3.0 [flex_seed_scheme flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid] - flutter_displaymode 0.6.0 [flutter] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_riverpod 2.4.3 [collection flutter meta riverpod state_notifier] - flutter_screenutil 5.9.0 [flutter] - flutter_slidable 3.0.5 [flutter] - flutter_svg 2.0.7 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_typeahead 4.8.0 [flutter flutter_keyboard_visibility pointer_interceptor] - fluttertoast 8.2.2 [flutter flutter_web_plugins] - font_awesome_flutter 10.5.0 [flutter] - geolocator 10.1.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - google_fonts 6.1.0 [flutter http path_provider crypto] - hive 2.2.3 [meta crypto] - hive_flutter 1.1.0 [flutter hive path_provider path] - home_widget 0.3.0 [flutter path_provider path_provider_foundation] - http 1.1.0 [async http_parser meta] - intl 0.18.1 [clock meta path] - introduction_screen 3.1.12 [flutter collection dots_indicator flutter_keyboard_visibility] - jovial_svg 1.1.18-rc.1 [xml collection args vector_math jovial_misc http meta flutter] - logger 2.0.2+1 - lottie 2.6.0 [archive flutter path vector_math] - material_design_icons_flutter 7.0.7296 [flutter] - package_info_plus 5.0.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - shared_preferences 2.2.1 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shimmer 3.0.0 [flutter] - url_launcher 6.1.14 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - weather_animation 0.0.3 [flutter json_annotation freezed_annotation] - weather_icons 3.0.0 [flutter] - workmanager 0.5.2 [flutter] dev dependencies: - build_runner 2.4.6 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] - hive_generator 2.0.1 [build source_gen hive analyzer source_helper] - msix 3.16.1 [args yaml path package_config get_it image pub_semver console cli_util] - package_rename 1.5.1 [args html logger yaml] transitive dependencies: - _fe_analyzer_shared 64.0.0 [meta] - _flutterfire_internals 1.3.7 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 6.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.4.5 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.4.1 [analyzer async convert crypto glob logging meta package_config path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 4.0.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.4.1 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml] - build_runner_core 7.2.11 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.6.3 [built_collection collection fixnum meta] - cached_network_image_platform_interface 3.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.1.0 [cached_network_image_platform_interface flutter flutter_cache_manager] - characters 1.3.0 - checked_yaml 2.0.3 [json_annotation source_span yaml] - cli_util 0.4.0 [meta path] - clock 1.1.1 - code_builder 4.7.0 [built_collection built_value collection matcher meta] - collection 1.17.2 - console 4.1.0 [vector_math] - convert 3.1.1 [typed_data] - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - dart_style 2.3.3 [analyzer args path pub_semver source_span] - device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface] - dots_indicator 2.1.2 [flutter] - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - ffi 2.1.0 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.7.1 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.5+1 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.8.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_performance_platform_interface 0.1.4+7 [_flutterfire_internals firebase_core flutter plugin_platform_interface] - firebase_performance_web 0.1.4+7 [_flutterfire_internals firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins js] - fixnum 1.1.0 - flex_seed_scheme 1.4.0 [collection flutter meta] - flutter_keyboard_visibility 5.4.1 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter] - flutter_keyboard_visibility_linux 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_macos 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_keyboard_visibility_windows 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - freezed_annotation 2.4.1 [collection json_annotation meta] - frontend_server_client 3.2.0 [async path] - geolocator_android 4.3.1 [flutter geolocator_platform_interface uuid] - geolocator_apple 2.3.2 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.1.1 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.2.0 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.2.1 [flutter geolocator_platform_interface] - get_it 7.6.4 [async collection] - glob 2.1.2 [async collection file path string_scanner] - graphs 2.3.1 [collection] - html 0.15.4 [csslib source_span] - http_multi_server 3.2.1 [async] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.1.3 [archive meta xml] - io 1.0.4 [meta path string_scanner] - jovial_misc 0.8.5 [pointycastle async collection convert meta] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - lints 2.1.1 - logging 1.2.0 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - mime 1.0.4 - octo_image 2.0.0 [flutter] - package_config 2.1.0 [path] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_parsing 1.0.1 [vector_math meta] - path_provider 2.1.1 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.2.0 [flutter path_provider_platform_interface] - path_provider_foundation 2.3.1 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.1 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32] - petitparser 5.4.0 [meta] - platform 3.1.3 - plugin_platform_interface 2.1.6 [meta] - pointer_interceptor 0.9.3+6 [flutter] - pointycastle 3.7.3 [collection convert js] - pool 1.5.1 [async stack_trace] - pub_semver 2.1.4 [collection meta] - pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml] - riverpod 2.4.3 [meta stack_trace state_notifier] - rxdart 0.27.7 - shared_preferences_android 2.2.1 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.3.4 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.3.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.3.1 [flutter plugin_platform_interface] - shared_preferences_web 2.2.1 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.3.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.1 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.4.0 [analyzer async build dart_style glob path source_span yaml] - source_helper 1.3.4 [analyzer collection source_gen] - source_span 1.10.0 [collection path term_glyph] - sqflite 2.3.0 [flutter sqflite_common path] - sqflite_common 2.5.0 [synchronized path meta] - stack_trace 1.11.0 [path] - state_notifier 1.0.0 [meta] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - synchronized 3.1.0 - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - timing 1.0.1 [json_annotation] - typed_data 1.3.2 [collection] - url_launcher_android 6.1.0 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.5 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.6 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.7 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.5 [flutter plugin_platform_interface] - url_launcher_web 2.0.20 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.8 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_graphics 1.1.7 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.7 - vector_graphics_compiler 1.1.7 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - watcher 1.1.0 [async path] - web 0.1.4-beta - web_socket_channel 2.4.0 [async crypto stream_channel] - win32 5.0.9 [ffi] - win32_registry 1.1.2 [ffi win32] - xdg_directories 1.0.3 [meta path] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

darshankawar commented 10 months ago

Thanks for the report @milindgoel15

  1. Use latest versions of firebase core, analytics, performance

Apart from firebase_core, analytics and performance plugins don't seem to yet support windows.

Can you try to single out / narrow down the reported behavior to specific flutterfire plugin and see if it consistently replicates the issue ?

milindgoel15 commented 10 months ago

analytics and performance plugins don't seem to yet support windows.

Yes, indeed.

Can you try to single out / narrow down the reported behavior to specific flutterfire plugin and see if it consistently replicates the issue ?

So, I tried out and found the issue to be in the firebase_core plugin, specially this specific PR. I tried out reverting both this PR and this one. But removing the commit from former PR seems to make it work. Then I tried out removing only the commit for this PR but then app fails to build altogether.

I copied all the debugger logs that came during the build process before failing: https://katb.in/ufoxikogobi

darshankawar commented 10 months ago

Thanks for the update and details. Keeping this issue open for team's attention / input.

/cc @cynthiajoan

Lyokone commented 10 months ago

@milindgoel15 Hi we have released new version of firebase_core, auth and firestore. Do you still see this behavior?

milindgoel15 commented 10 months ago

@milindgoel15 Hi we have released new version of firebase_core, auth and firestore. Do you still see this behavior?

Yes, the issue still persists. The debugger connection immediately breaks once it shows connecting to VM service

milindgoel15 commented 10 months ago

I am finally able to reproduce the issue. I can paste a link to the reproducible repo below but I don't think I should add firebase_options.dart file in the repo so to reproduce, you would create a fresh firebase project with configuration for any platform. I added android and web so that should be enough for the start.

To create a reproducible repo from scratch:

steps to reproduce 1. Create fresh flutter project 2. Create fresh firebase project 3. use flutterfire cli to add that firebase project to flutter project 4. add latest firebase_core dependency (2.16.0 to 2.19.0 anything will do) 5. add firebase initialise code in the main function but replace this code block: ```dart await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); ``` to ```dart await Firebase.initializeApp( options: DefaultFirebaseOptions.web, // or android depending upon config but both will cause the error ); ``` After doing these steps, the connection issue will be reproducible.

Generally, we shouldn't use Android or web as a Firebase platform in the initializer if we are running the app on a different platform and we should use the current platform. However, I am unsure how some of the Firebase plugins are supported on Windows since we cannot run a Windows app with the above configurations and since the Flutterfire cli cannot generate Firebase options for Windows and using the currentPlatform throws unsupported error:

      case TargetPlatform.windows:
        throw UnsupportedError(
          'DefaultFirebaseOptions have not been configured for windows - '
          'you can reconfigure this by running the FlutterFire CLI again.',
        );

I have no idea how the firebase_core plugin was handled before 2.16.0.

Lyokone commented 10 months ago

@milindgoel15 To support Windows, you can manually create a project on the Firebase Console, and add the relevant information in the TargetPlatform.windows (for quick debugging you can reuse the Android conf). The FlutterFire CLI is not yet updated to automatically add the config.

milindgoel15 commented 10 months ago

@milindgoel15 To support Windows, you can manually create a project on the Firebase Console, and add the relevant information in the TargetPlatform.windows (for quick debugging you can reuse the Android conf). The FlutterFire CLI is not yet updated to automatically add the config.

Tried replacing the throw statement to return android; and also duplicating the android config to Windows and running the app in both cases, app still fails to launch.

Lyokone commented 10 months ago

I've managed to reproduce the bug, I'll post updates soon :) Thanks for your help finding it

milindgoel15 commented 10 months ago

@Lyokone one more thing not related to this issue, when we build a Windows app including Firebase for the first time, it lists lots of errors in the debug console related to syntax errors, tag missing errors, etc. Though they do not cause any issues or don't seem to cause any but was just curious if they should be fixed. You might have noticed them as well ig

Lyokone commented 10 months ago

Most of them are directly part of the Firebase C++ SDK and depend on the configuration of Flutter and how it compiles C++ libraries, not sure if it's something that we will be able to get ride of easily

Lyokone commented 9 months ago

The fix is in master and will be released as part of the next release