android - 缺少插件异常(在 channel plugins.flutter.io/firebase_core 上找不到方法 firebase#initializecore 的实现)

标签 android firebase flutter flutter-desktop

错误描述
我在 Windows 桌面上运行我的 flutter 应用程序
我在 android studio 中使用主 channel 以便在桌面上运行它。
我已将 firebase 集成到我的应用程序中,并且登录注册工作正常,但是当我尝试从我的云 firestore 添加或获取数据时,错误似乎是“没有创建 Firebase 应用程序'[DEFAULT]' - 调用 Firebase Flutter 和 Firebase 中的 .initializeApp()",通过添加解决

void main()
async
{
   WidgetsFlutterBinding.ensureInitialized();
   await Firebase.initializeApp();
   // if (USE_FIRESTORE_EMULATOR) {
   //   FirebaseFirestore.instance.settings = Settings(
   //       host: 'localhost:8080', sslEnabled: false, persistenceEnabled: false);
   // }
  runApp(MyApp());
}
到我的应用程序。
但添加后我得到了这个错误:
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Debug service listening on ws://127.0.0.1:14281/b7FohxM2yN4=/ws
Syncing files to device Windows...
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
<asynchronous suspension>
#1      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:35)
<asynchronous suspension>
#2      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:22)
<asynchronous suspension>
#3      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75:7)
<asynchronous suspension>
#4      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:9)
<asynchronous suspension>
#5      main (package:res_ds/main.dart:17:4)
<asynchronous suspension>
这就是我无法解决的错误。出现此错误后,我的应用程序 GUI 未显示。
我尝试了多种互联网上可用的解决方案,但没有一个对我有用。
我在下面提供了 flutter 医生和 pubspec,请看看并帮助我解决这个问题。
提前致谢
flutter 医生
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 1.27.0-2.0.pre.67, on Microsoft Windows [Version 10.0.19041.804], locale 
en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.52.1)
[√] Connected device (1 available)

! Doctor found issues in 1 category.
发布规范.yaml
name: res_ds
description: A new Flutter application.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  provider: ^4.3.2+2
  http: ^0.12.2
  cloud_firestore: ^0.14.2
  firebase_core: ^0.5.0
  image_picker: ^0.6.7+22


dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
     - assets/images/
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

最佳答案

Flutter Firebase 插件 do not currently support Windows ,这就是为什么在 Windows 上运行时没有插件实现的原因。

关于android - 缺少插件异常(在 channel plugins.flutter.io/firebase_core 上找不到方法 firebase#initializecore 的实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66259416/

相关文章:

flutter 包 : Uncompressed package archive is too large

java - 如何使用可序列化将类对象存储到内部存储器中?

android - 使低分辨率图像看起来不错

java - Android 中的 HttpConnect 失败

Android:应用程序服务器上的 GCM 推送通知错误 "SENDER_ID_MISMATCH"

ios - 在 swift 中从 firebase 检索数组元素

Android fragment 复制

android - 如何使用 Firebase 进行自定义身份验证?

file - 如何在Flutter中获取文件扩展名?

firebase - 如何根据特定条件显示/隐藏按钮?