简体   繁体   English

flutter MissingPluginException 上的 Firebase 初始化错误

[英]Firebase initialization error on flutter MissingPluginException

I am developing an app in flutter I am using firebase in this app.我正在 flutter 中开发一个应用程序我在这个应用程序中使用 firebase。 And I am using following dependencies:我正在使用以下依赖项:

firebase_messaging: ^10.0.0
firebase_core: ^1.2.0
cloud_firestore: ^2.2.0
firebase_storage: ^8.1.0

I am initializing firebase like this:我正在像这样初始化 firebase:

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

This whole code was working fine till today's morning but after that it is giving this error everytime:直到今天早上,整个代码都运行良好,但之后每次都会出现此错误:

Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:53273/b_8_mVgWJY0=/ws
Syncing files to device sdk gphone x86...
I/flutter (15902): completed
E/flutter (15902): [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)
E/flutter (15902): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter (15902): <asynchronous suspension>
E/flutter (15902): #1      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:344:35)
E/flutter (15902): <asynchronous suspension>
E/flutter (15902): #2      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:23)
E/flutter (15902): <asynchronous suspension>
E/flutter (15902): #3      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:77:7)
E/flutter (15902): <asynchronous suspension>
E/flutter (15902): #4      Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)
E/flutter (15902): <asynchronous suspension>
E/flutter (15902): 

Is there anything wrong with android studio or flutter SDK itself? android studio 或 flutter SDK 本身有什么问题吗? I have also noticed that there is one file generated that was not there earlier when the app was working fully functional the file is named "generated_plugin_registrant.dart".我还注意到,当应用程序完全正常运行时,生成了一个文件,该文件名为“generated_plugin_registrant.dart”。

Update : I removed flutter from my windows and again installed it but it didn't work as well.更新:我从我的 windows 中删除了 flutter 并再次安装了它,但它没有正常工作。 Now I think I should uninstall android studio completely and again install it because I don't find any error or wrong implementation in my code till now, Please tell me if there is any.现在我想我应该完全卸载 android studio 并重新安装它,因为到目前为止我在我的代码中没有发现任何错误或错误的实现,请告诉我是否有任何错误。

Please help me.请帮我。

Thanks for your replies.感谢您的回复。

I searched a lot on the internet but the solution was very simple.我在互联网上搜索了很多,但解决方案非常简单。 It was happening because the following code was missing in my MainActivity.kt .发生这种情况是因为我的MainActivity.kt中缺少以下代码。 Code:代码:

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); } override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); } GeneratedPluginRegistrant.registerWith(flutterEngine); }

It was not registering the flutter plugins that's why it was giving an error it took me 2 and a half days I hope if someone else is facing this issue they can solve it earlier than me.它没有注册 flutter 插件,这就是为什么它给出了一个错误,我花了 2 天半的时间我希望如果其他人遇到这个问题,他们可以比我更早解决它。

And thanks for all your replies.并感谢您的所有回复。

Try running尝试运行

flutter clean
flutter pub get

in the terminal and see if that helps在终端中,看看是否有帮助

Have you tried running flutter clean in the terminal?您是否尝试过在终端中运行 flutter clean ?

flutter clean

and then接着

flutter pub get

edit:编辑:

Or, in android/build.gradle under dependencies , you could use another version of gradle build tools if it helps或者,在dependencies项下的android/build.gradle中,如果有帮助,您可以使用另一个版本的 gradle 构建工具

classpath 'com.android.tools.build:gradle:3.5.0'

I had the same problem.我有同样的问题。 I also tried many solution like you, but could not able to resolve it issues.我也尝试了很多像你一样的解决方案,但无法解决它的问题。

Latter, I ended up creating a new project carefully copying firebase and multiple other packages from the original project.后来,我最终创建了一个新项目,从原始项目中仔细复制了 firebase 和多个其他包。 After that I copied every single file in lib/android along with their respective configurations in build.gradle and manifests.之后,我复制了 lib/android 中的每个文件以及它们各自在 build.gradle 和清单中的配置。 For iOS I just copied the entire project and that worked immediately.对于 iOS,我刚刚复制了整个项目,并且立即生效。

You also can try like my.你也可以像我一样试试。 Create a new project and copy everything from your old project to new one, one by one to see this issue resolved or not.创建一个新项目并将旧项目中的所有内容复制到新项目中,一一查看此问题是否已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Firebase 实时数据库 MissingPluginException - Flutter Firebase Realtime Database MissingPluginException 无法在 Flutter 中集成 Firebase - MissingPluginException - Cannot integrate Firebase in Flutter - MissingPluginException Flutter web Firebase 初始化错误 - Flutter web Firebase initialization error 连接到 Firestore 时出错:flutter,MissingPluginException - Error Connecting to Firestore: flutter, MissingPluginException Flutter web 开发与 Firebase 身份验证:MissingPluginException - Flutter web Dev with Firebase auth: MissingPluginException Flutter 应用程序未连接到 Firebase:抛出 MissingPluginException - Flutter App does not Connect to Firebase: MissingPluginException thrown Firebase 初始化异常 flutter - Firebase initialization Exception in flutter 使用 flutter (windows) 应用程序进行 firebase 匿名登录时出现 MissingPluginException 异常 - MissingPluginException exception when a firebase anonymous sign-in with flutter (windows) app Firebase Flutter iOS初始化问题 - Firebase Flutter iOS initialization issue Flutter Firestore 错误:MissingPluginException(找不到方法 DocumentReference#updateData 的实现 - Flutter Firestore Error: MissingPluginException(No implementation found for method DocumentReference#updateData
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM