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.72k stars 3.97k forks source link

๐Ÿ› [firebase_core] Firebase.initializeApp hangs #9204

Closed Mijawel closed 2 years ago

Mijawel commented 2 years ago

Bug report

Describe the bug

print('starting app');
    if (Firebase.apps.isEmpty) {
      try {
        await Firebase.initializeApp(
            options: DefaultFirebaseOptions.currentPlatform);
      } catch (e) {}
    }
print('firebase inited');

This code hangs and the second print call never runs.

Steps to reproduce

Steps to reproduce the behavior: I updated my firebase_core (firestore, auth, functions) to the latest versions in pubspec.yaml and used 'flutterfire configure' to make sure my configuration was up to date.

In the past I was adding the sdks directly in the index.html following the manual installation as described here https://firebase.flutter.dev/docs/manual-installation/web/

But this time instead I set it up following these up to date instructions: https://firebase.google.com/docs/flutter/setup?platform=web

I have recreated the error in a sample project below.

Expected behavior

Firebase should init without hanging indefinitely.

Sample project

https://github.com/Mijawel/firebase_hang_example

I have included a basic project which shows the error along with the pubspec of the original project where i encountered the issue.


Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[โœ“] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-arm, locale en-AU)
[โœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[โœ“] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[โœ“] Chrome - develop for the web
[โœ“] Android Studio
[โœ“] Android Studio (version 2021.2)
[โœ“] VS Code (version 1.69.2)
[โœ“] Connected device (2 available)
[โœ“] HTTP Host Availability

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.17.0 Flutter SDK 3.0.0 chazara 1.0.29+29 dependencies: - audio_session 0.1.6+1 [flutter flutter_web_plugins rxdart meta] - auto_size_text 3.0.0-nullsafety.0 [flutter] - avatars 3.0.2 [flutter crypto flutter_cache_manager] - camera 0.9.4+3 [camera_platform_interface camera_web flutter pedantic quiver flutter_plugin_android_lifecycle] - carousel_slider 4.0.0 [flutter] - cloud_firestore 3.4.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_firestore_web 2.8.0 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions 3.3.3 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - contextmenu 3.0.0 [flutter animations after_layout] - cupertino_icons 1.0.3 - editor_js 2.5.0 [flutter flutter_inappwebview visibility_detector flutter_keyboard_visibility flex_color_picker file_picker numberpicker pointer_interceptor pedantic meta] - envify 2.0.2 - ffmpeg_kit_flutter_audio 4.5.1 [ffmpeg_kit_flutter_platform_interface flutter] - firebase_auth 3.5.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.20.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.7.2 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_inset_box_shadow 1.0.8 [flutter] - flutter_local_notifications 9.1.2 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_platform_widgets 1.20.0 [flutter] - flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows] - flutter_sound 9.1.2 [path_provider recase uuid provider path synchronized logger flutter flutter_sound_platform_interface flutter_sound_web] - flutter_webrtc 0.8.9 [dart_webrtc flutter path_provider webrtc_interface] - font_awesome_flutter 10.1.0 [flutter] - hive 2.0.4 [meta crypto] - hive_flutter 1.1.0 [flutter hive path_provider path] - html 0.15.0 [csslib source_span] - http 0.13.4 [async http_parser meta path] - image_picker 0.8.4+3 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface] - logger 1.1.0 - measured_size 1.0.0 [flutter] - path 1.8.1 - path_provider 2.0.5 [flutter path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - permission_handler 8.3.0 [flutter meta permission_handler_platform_interface] - platform 3.1.0 - pointer_interceptor 0.9.3+2 [flutter] - provider 6.0.2 [collection flutter nested] - reorderables 0.5.0 [flutter] - responsive_builder 0.4.2 [flutter] - sizer 2.0.15 [universal_io flutter] - text_recognition 0.0.1 [flutter] - url_launcher 6.1.2 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - youtube_player_iframe 2.3.0 [flutter url_launcher] dev dependencies: - build_runner 2.1.4 [args async analyzer 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] - change_app_package_name 1.1.0 - envify_generator 2.0.2 [analyzer build dotenv envify path source_gen] - flutter_launcher_icons 0.9.2 [args image path yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - hive_generator 1.1.1 [build source_gen hive analyzer source_helper] - test 1.20.2 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core] transitive dependencies: - _fe_analyzer_shared 30.0.0 [meta] - after_layout 1.2.0 [flutter] - analyzer 2.7.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - animations 2.0.3 [flutter] - archive 3.1.6 [crypto path] - args 2.3.0 - async 2.8.2 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.1.1 [analyzer async convert crypto glob logging meta path] - build_config 1.0.0 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.0.1 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.4 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.2 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.1.2 [built_collection collection fixnum meta] - camera_platform_interface 2.1.1 [cross_file flutter meta plugin_platform_interface stream_transform] - camera_web 0.2.1+1 [camera_platform_interface flutter flutter_web_plugins stream_transform] - characters 1.2.0 - charcode 1.3.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.0 - cloud_firestore_platform_interface 5.7.0 [collection firebase_core flutter meta plugin_platform_interface] - cloud_functions_platform_interface 5.1.12 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.3.1 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 4.1.0 [built_collection built_value collection matcher meta] - collection 1.16.0 - convert 3.0.1 [typed_data] - coverage 1.0.3 [args logging package_config path source_maps stack_trace vm_service] - cross_file 0.3.1+5 [flutter meta] - crypto 3.0.1 [collection typed_data] - csslib 0.17.2 [source_span] - dart_style 2.2.0 [analyzer args path pub_semver source_span] - dart_webrtc 1.0.6 [webrtc_interface] - dbus 0.5.6 [args ffi meta pedantic xml] - dotenv 3.0.0 [args meta] - fake_async 1.3.0 [clock collection] - ffi 1.1.2 - ffmpeg_kit_flutter_platform_interface 0.2.1 [flutter plugin_platform_interface] - file 6.1.2 [meta path] - file_picker 4.6.1 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - firebase_auth_platform_interface 6.4.0 [collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 4.1.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.5.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 1.7.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.2.6 [collection firebase_core flutter meta plugin_platform_interface] - fixnum 1.0.0 - flex_color_picker 2.5.0 [flutter material_color_utilities] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_inappwebview 5.4.3+7 [flutter] - flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web 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_local_notifications_linux 0.3.0 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.4 [flutter] - flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_sound_platform_interface 9.1.2 [flutter meta plugin_platform_interface logger] - flutter_sound_web 9.1.2 [flutter_sound_platform_interface flutter logger flutter_web_plugins meta js] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 2.1.2 [async path] - glob 2.0.2 [async collection file path string_scanner] - graphs 2.1.0 [collection] - http_multi_server 3.0.1 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 3.1.0 [archive meta xml] - image_picker_for_web 2.1.4 [flutter flutter_web_plugins image_picker_platform_interface meta] - image_picker_platform_interface 2.4.1 [flutter http meta plugin_platform_interface cross_file] - infinite_listview 1.1.0 [flutter] - intl 0.17.0 [clock path] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - json_annotation 4.3.0 [meta] - logging 1.0.2 - matcher 0.12.11 [stack_trace] - material_color_utilities 0.1.4 - meta 1.7.0 - mime 1.0.1 - nested 1.0.0 [flutter] - node_preamble 2.0.1 - numberpicker 2.1.1 [flutter infinite_listview] - package_config 2.0.2 [path] - path_provider_linux 2.1.0 [flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.2 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.3 [ffi flutter meta path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - petitparser 4.4.0 [meta] - plugin_platform_interface 2.0.2 [meta] - pool 1.5.0 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.0 [collection meta] - pubspec_parse 1.1.0 [checked_yaml collection json_annotation pub_semver yaml] - quiver 3.0.1+1 [matcher] - recase 4.0.0 - rxdart 0.27.3 - shelf 1.2.0 [async collection http_parser path stack_trace stream_channel] - shelf_packages_handler 3.0.0 [path shelf shelf_static] - shelf_static 1.1.0 [convert http_parser mime path shelf] - shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.1.1 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.0 [analyzer collection source_gen] - source_map_stack_trace 2.1.0 [path stack_trace source_maps] - source_maps 0.10.10 [source_span] - source_span 1.8.2 [collection path term_glyph] - sqflite 2.0.1 [flutter sqflite_common path] - sqflite_common 2.1.0 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.4.11 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api] - timezone 0.8.0 [path] - timing 1.0.0 [json_annotation] - typed_data 1.3.0 [collection] - universal_io 2.0.4 [collection crypto meta typed_data] - url_launcher_android 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface] - url_launcher_web 2.0.11 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface] - uuid 3.0.5 [crypto] - vector_math 2.1.2 - visibility_detector 0.3.3 [flutter] - vm_service 7.3.0 - watcher 1.0.1 [async path] - web_socket_channel 2.1.0 [async crypto stream_channel] - webkit_inspection_protocol 1.0.0 [logging] - webrtc_interface 1.0.5 - win32 2.6.1 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

Lyokone commented 2 years ago

Hey, I'm taking a look

Lyokone commented 2 years ago
 if (Firebase.apps.isEmpty) {

In your code, you're catching an error (in the zone guard) without displaying it. If you print the error, you see that you need to initialise a first app before calling Firebase.apps.

So this code will not hang:

  runZonedGuarded<Future<void>>(() async {
    Logger.level = Level.verbose;
    WidgetsFlutterBinding.ensureInitialized();
    print('starting app');
    try {
      await Firebase.initializeApp(
          options: DefaultFirebaseOptions.currentPlatform);
    } catch (e) {}
    print('firebase inited');

    runApp(MyApp());
  }, (error, stack) {
    if (!kIsWeb)
      FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
  });

Since you're running the main once, your list of app is always empty at first.

Mijawel commented 2 years ago

Thanks that worked. I think since on the older version of firebase I was initializing it manually in a script in index.html so the issue was masked.