【问题标题】:missingpluginexception(no implementation found for method firebase#initializecore on channel plugins.flutter.io/firebase_core)缺少插件异常(在通道 plugins.flutter.io/firebase_core 上找不到方法 firebase#initializecore 的实现)
【发布时间】:2021-05-21 08:57:09
【问题描述】:

错误说明 我在 Windows 桌面上运行我的颤振应用程序 我在 android studio 中使用主通道以便在桌面上运行它。 我已将 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 不显示。 我尝试了多种互联网上可用的解决方案,但没有一个对我有用。 我在下面提供了颤振医生和 pubspec,请看看并帮助我解决这个问题。 提前致谢 颤振医生

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.

Pubspec.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

【问题讨论】:

标签: android firebase flutter flutter-desktop


【解决方案1】:

因为 firebase 不支持 Windows,所以我这样做了,无论我在哪里使用 firebase 类,我都设置了这个条件,问题就解决了......

void main() async {
  Bloc.observer = PishBlocObserver(); //log Bloc/cubit
  WidgetsFlutterBinding.ensureInitialized();
  
  (!Platform.isWindows) ? await Firebase.initializeApp() : null;
  FirebaseMessaging.onBackgroundMessage(resiveNotiInBackGround);

  runApp(....

 gettokan() async {
      await FirebaseMessaging.instance.getToken().then((value) {
        print(value);
      });
    }

   (!Platform.isWindows) ? gettokan() : null;

和...

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我不确定为什么人们不赞成这个答案。这个问题的错误原因是插件实现不存在 for Windows。尝试针对他们在网上找到的错误消息的各种解决方案不起作用的原因是,在这种特殊情况下,错误的根源不是配置错误,而是没有没有实现。我已链接到该插件的权威来源,其中列出了它支持的平台,但不包括 Windows。
    • 我目前正在编写一个桌面颤振应用程序,它与 Android/IOS 应用程序共享很多代码,并得到同样的错误。我的应用程序使用了几个未列出 windows 的包,但没问题。 fireart 包明确声明它是“dart native”。所以我猜firebase不是“dart native”。如果有人解释这些“渠道”的含义,这将有助于我的理解。从飞镖到用另一种语言编写的代码的桥梁?最后我想知道为什么 Google 说 Flutter 2.2 支持 Windows,但像 Firebase 这样的重要包还不支持。
    • @MichaelUhlenberg 大多数软件包适用于所有平台;插件是具有本机、特定于平台的代码的包。有关频道的说明,请参阅flutter.dev/docs/development/platform-integration/…。至于支持 Windows,Firebase 本身并没有 Windows 桌面支持。没有适用于 iOS 和 Android 的 Windows Firebase SDK。 Flutter 不是 Firebase,就像它不是许多其他插件中的任何一个一样,支持一个平台并不意味着每个可能的插件都会支持该平台。
    猜你喜欢
    • 2021-11-03
    • 2022-01-21
    • 2022-01-25
    • 2021-12-31
    • 2021-05-28
    • 2022-01-05
    • 2021-12-24
    • 2020-07-21
    相关资源
    最近更新 更多