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.63k stars 3.95k forks source link

[Firebase_core] Firebase.initializeApp doesn't return #7071

Closed Hu1buerger closed 2 years ago

Hu1buerger commented 2 years ago

Bug report

Describe the bug await Firebase.initializeApp() doesn't return at all when running as WidgetTest.

Steps to reproduce

Steps to reproduce the behavior:

  1. write a test
  2. run the test

The test should look like that

import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('Test recieve message', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());

    // Build our app and trigger a frame.
    WidgetsFlutterBinding.ensureInitialized();
    var fireApp = await Firebase.initializeApp(
        options: FirebaseOptions(
      projectId: "REDACTED",
      appId: 'REDACTED',
      messagingSenderId: 'REDACTED',
      apiKey: 'REDACTED',
    ));

    do_somefurther_test();
  });
}

We initially just tried with Firebase.initializeApp() but same behaviour.

We traced the call

#0      TestDefaultBinaryMessenger.Eval ()
#1      TestDefaultBinaryMessenger.send (package:flutter_test/src/binding.dart:104:45)
#2      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:52)
#3      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
#4      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:41)
#5      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:37)
#6      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:77:13)
#7      Firebase.initializeApp (package:firebase_core/src/firebase.dart:42:47)
#8      main.<anonymous closure> (file:///Users/user/Documents/Developer/rbyte-app/test/page_chat_test.dart:16:34)
<asynchronous suspension>
#9      StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart)
<asynchronous suspension>

Expected behavior

I expect that the call to Firebase.initializeApp() returns and Β΄do_somefurther_test()` gets executed. It should behave just like when running as app.

Sample project

see above code.

Additional context

The call with the same argument returns when run as an app via flutter run


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [βœ“] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-x64, locale en-DE) β€’ Flutter version 2.2.3 at /usr/local/Caskroom/flutter/2.2.3/flutter β€’ Framework revision f4abaa0735 (3 months ago), 2021-07-01 12:46:11 -0700 β€’ Engine revision 241c87ad80 β€’ Dart version 2.13.4 [βœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0) β€’ Android SDK at /Users/user/Library/Android/sdk β€’ Platform android-31, build-tools 31.0.0 β€’ Java binary at: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java β€’ Java version Java(TM) SE Runtime Environment (build 1.8.0_301-b09) β€’ All Android licenses accepted. [βœ—] Xcode - develop for iOS and macOS βœ— Xcode installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch βœ— CocoaPods not installed. CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version 2020.3) β€’ Android Studio at /Applications/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 βœ— Unable to find bundled Java version. β€’ Try updating or re-installing Android Studio. [βœ“] IntelliJ IDEA Ultimate Edition (version 2021.2) β€’ IntelliJ at /Applications/IntelliJ IDEA.app β€’ Flutter plugin version 60.1.4 β€’ Dart plugin version 212.4746.57 [βœ“] VS Code (version 1.60.0) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension can be installed from: πŸ”¨ https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [βœ“] Connected device (2 available) β€’ sdk gphone x86 (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 11 (API 30) (emulator) β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 93.0.4577.82 ! Doctor found issues in 2 categories. ```

Flutter dependencies

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

Click To Expand ``` PASTE OUTPUT INSIDE HERE ```

markusaksli-nc commented 2 years ago

Hi @Hu1buerger Could you please flutter upgrade to the latest stable and provide your flutter pub deps -- --style=compact? Thank you

Hu1buerger commented 2 years ago

Did flutter upgrade to the latest stable and will now provide pub deps

Dart SDK 2.14.2
Flutter SDK 2.5.1
REDACTED 0.6.0

dependencies:
- cached_network_image 3.1.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- carousel_slider 4.0.0 [flutter]
- cloud_firestore 2.5.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- connectivity 3.0.6 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- cupertino_icons 1.0.3
- disposables 1.0.0 [quiver]
- file_picker 4.0.1 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path]
- firebase_analytics 8.3.1 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta]
- firebase_auth 3.1.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.6.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 10.0.6 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 10.0.3 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_chat_ui 1.3.3 [flutter diffutil_dart equatable flutter_chat_types flutter_link_previewer intl meta photo_view]
- flutter_firebase_chat_core 1.3.1 [flutter cloud_firestore firebase_auth flutter_chat_types meta]
- flutter_launcher_icons 0.9.2 [args image path yaml]
- flutter_local_notifications 8.1.1+2 [flutter flutter_local_notifications_platform_interface platform timezone]
- flutter_phoenix 1.0.0 [flutter]
- flutter_search_bar 3.0.0-dev.1 [flutter meta]
- flutter_secure_storage 4.2.1 [meta flutter]
- flutter_staggered_grid_view 0.4.0 [flutter]
- fluttertoast 8.0.8 [flutter flutter_web_plugins]
- font_awesome_flutter 9.1.0 [flutter]
- geoflutterfire 3.0.1 [flutter cloud_firestore rxdart]
- google_maps_flutter 2.0.8 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- google_sign_in 5.1.0 [flutter google_sign_in_platform_interface google_sign_in_web meta]
- http 0.13.3 [async http_parser meta path pedantic]
- image_picker 0.8.4 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- json_serializable 4.1.4 [analyzer build build_config collection json_annotation meta path source_gen]
- location 4.3.0 [flutter location_platform_interface location_web]
- logging 1.0.1
- multi_image_picker 4.8.01 [flutter meta]
- open_file 3.2.1 [flutter ffi]
- package_info_plus 1.0.6 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- path_provider 2.0.3 [flutter path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- pdf 3.5.0 [archive barcode crypto image meta path_parsing vector_math xml]
- printing 5.5.0 [ffi flutter flutter_web_plugins http image js meta pdf plugin_platform_interface]
- qr 2.1.0 [meta]
- rxdart 0.27.2
- url_launcher 6.0.10 [flutter meta url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- youtube_player_flutter 8.0.0 [flutter flutter_inappwebview]
- youtube_player_iframe 2.2.2 [flutter flutter_inappwebview url_launcher]

dev dependencies:
- build_runner 2.1.2 [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 pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- change_app_package_name 1.0.0
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- _fe_analyzer_shared 22.0.0 [meta]
- analyzer 1.7.1 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml pedantic]
- archive 3.1.2 [crypto path]
- args 2.2.0
- async 2.6.1 [meta collection]
- barcode 2.1.0 [meta qr]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.1.0 [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.0 [built_collection built_value http_multi_server logging pedantic 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.1.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.1.2 [built_collection collection fixnum meta]
- cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.1.0
- charcode 1.2.0
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- cli_util 0.3.3 [meta path]
- clock 1.1.0
- cloud_firestore_platform_interface 5.4.1 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.4.1 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.1.0 [built_collection built_value collection matcher meta]
- collection 1.15.0
- connectivity_for_web 0.4.0+1 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.2.1+2 [flutter connectivity_platform_interface]
- connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- convert 3.0.1 [typed_data]
- cross_file 0.3.1+4 [flutter meta]
- crypto 3.0.1 [collection typed_data]
- csslib 0.17.0 [source_span]
- dart_style 2.0.3 [analyzer args path pub_semver source_span]
- diffutil_dart 2.0.0+1
- equatable 2.0.3 [collection meta]
- fake_async 1.2.0 [clock collection]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase 9.0.1 [http http_parser js]
- firebase_analytics_platform_interface 2.0.1 [flutter meta]
- firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta]
- firebase_auth_platform_interface 6.1.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 3.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.0.1 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 3.0.5 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 2.0.5 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 4.0.2 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.0.2 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.0
- flutter_blurhash 0.6.0 [flutter meta pedantic]
- flutter_cache_manager 3.1.2 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_chat_types 3.0.1 [equatable json_annotation meta]
- flutter_inappwebview 5.3.2 [flutter]
- flutter_link_previewer 2.4.1 [flutter flutter_chat_types flutter_linkify html http linkify meta url_launcher]
- flutter_linkify 5.0.2 [flutter linkify]
- flutter_local_notifications_platform_interface 4.0.1 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.3 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- frontend_server_client 2.1.2 [async path]
- glob 2.0.1 [async collection file path pedantic string_scanner]
- google_maps_flutter_platform_interface 2.1.1 [collection flutter meta plugin_platform_interface stream_transform]
- google_sign_in_platform_interface 2.0.1 [flutter meta quiver]
- google_sign_in_web 0.10.0+2 [flutter flutter_web_plugins google_sign_in_platform_interface js meta]
- graphs 2.0.0
- html 0.15.0 [csslib source_span]
- http_multi_server 3.0.1 [async]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.0.2 [archive meta xml]
- image_picker_for_web 2.1.3 [flutter flutter_web_plugins image_picker_platform_interface meta]
- image_picker_platform_interface 2.4.1 [flutter http meta plugin_platform_interface cross_file]
- io 1.0.3 [meta path string_scanner]
- js 0.6.3
- json_annotation 4.0.1
- linkify 4.1.0
- location_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- location_web 3.1.1 [flutter flutter_web_plugins http_parser js location_platform_interface meta]
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- mime 1.0.0
- octo_image 1.0.0+1 [flutter flutter_blurhash]
- package_config 2.0.0 [path]
- package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.1.1 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 1.0.3 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.0
- path_parsing 0.2.1 [vector_math meta]
- path_provider_linux 2.0.2 [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
- petitparser 4.1.0 [meta]
- photo_view 0.12.0 [flutter]
- platform 3.0.2
- plugin_platform_interface 2.0.1 [meta]
- pool 1.5.0 [async stack_trace]
- process 4.2.3 [file path platform]
- pub_semver 2.0.0 [collection]
- pubspec_parse 1.0.0 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.0.1 [matcher]
- shelf 1.2.0 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.0.3 [analyzer async build dart_style glob meta path pedantic source_span yaml]
- source_span 1.8.1 [collection path term_glyph]
- sqflite 2.0.0+4 [flutter sqflite_common path]
- sqflite_common 2.0.1 [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.3.0 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- timing 1.0.0 [json_annotation]
- typed_data 1.3.0 [collection]
- url_launcher_linux 2.0.2 [flutter]
- url_launcher_macos 2.0.2 [flutter]
- url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface]
- url_launcher_web 2.0.4 [flutter flutter_web_plugins meta url_launcher_platform_interface]
- url_launcher_windows 2.0.2 [flutter]
- uuid 3.0.4 [crypto]
- vector_math 2.1.0
- watcher 1.0.0 [async path pedantic]
- web_socket_channel 2.1.0 [async crypto stream_channel]
- win32 2.2.9 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 5.1.2 [collection meta petitparser]
- yaml 3.1.0 [collection source_span string_scanner]
markusaksli-nc commented 2 years ago

I would say that the FlutterFire plugins rely on delegating calls to the native SDKs to initialize and provide functionality and as with most unit tests these kinds of external dependencies are usually mocked (read https://flutter.dev/docs/testing#unit-tests for more). You can take a look at how the tests in this repository are structured for example.

That being said it doesn't look right that it just doesn't return instead of throwing?

Hu1buerger commented 2 years ago

Yes definitely. But I would argue that even while testing, testing against - dear lord I am so sorry; I repent my sins - production database should be possible. I.e. for testing Widgets

Hu1buerger commented 2 years ago

@markusaksli-nc Is this issue also present for flutter desktop? I would assume that this would be an issue bcs this would break firebase for flutter desktop.

markusaksli-nc commented 2 years ago

You mean not returning because it isn't supported? On Linux and Windows the plugins will just throw because the channels aren't implemented for the platform. The ones that aren't yet supported on macOS should do the same.

Hu1buerger commented 2 years ago

no i would argue that the desktop implementation should be supported, but I hear that you seem to be planing that.

But also I am not sure on what platform unit tests for android run. But maybe they run on the dev platform under the assumption that any widget should also run on that platform.

markusaksli-nc commented 2 years ago

Unit tests do not run on real device hardware through an OS. That's what integration tests are for. This is why it shouldn't be possible to test against your production database in unit tests as well. The FlutterFire plugins rely on method channels to communicate with the native Firebase SDK on the target device. In unit tests, this needs to be mocked or it can't be used at all.

qiansen1386 commented 2 years ago

@markusaksli-nc How about automated integration test with firesbase-emulators? Any clue on how to achieve that? Because anytime I call await Firebase.initializeApp(); I got No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core error

russellwheatley commented 2 years ago

We have provided documentation on how to run unit tests and integration tests here. Hope this help!