简体   繁体   English

MissingPluginException(在 Android 上找不到方法 Firebase#initializeCore 在通道插件上的实现。flutter.io/firebase_core)

[英]MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) on Android

I am getting the above error when calling Firebase.initializeApp() in my flutter code.在我的 flutter 代码中调用Firebase.initializeApp()时出现上述错误。 I have followed the documentation here: https://firebase.flutter.dev/docs我在这里遵循了文档: https://firebase.flutter.dev/docs

Here is my pubspec.yaml这是我的 pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^0.5.0
  cloud_firestore: ^0.14.0
  firebase_auth: ^0.18.0
  fl_chart: ^0.11.0
  snapping_sheet: ^2.0.0
  flutter_svg: ^0.18.0
  flutter_redux: ^0.6.0
  strings: ^0.1.2
  random_string: ^2.1.0
  redux_thunk: ^0.3.0
  #  firebase_crashlytics: ^0.1.4+1
  dotted_line: ^2.0.1

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

Here is my flutter code:这是我的 flutter 代码:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);

  final store = Store<AppState>(AppState.reducer, initialState: AppState.initial(), middleware: [thunkMiddleware]);

  runApp(
    FutureBuilder(
      future: Firebase.initializeApp(),
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          log(snapshot.error.toString());
          return Container(color: Colors.red);
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return StoreProvider<AppState>(
            store: store,
            child: MoollaApp(store: store),
          );
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Container(color: Colors.green);
      },
    ),
  );
}

Here are the relevant part of my.gradle (app) file:以下是 my.gradle (app) 文件的相关部分:

plugins {
    id "com.android.application"
    id "com.google.gms.google-services"
    id "kotlin-android"
    id "kotlin-android-extensions"
}

Here is my project gradle file:这是我的项目 gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0-alpha07'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and my Application class extension:和我的申请 class 分机号:

class MyApp : FlutterApplication() {
    override fun onCreate() {
        super.onCreate()
    }
}

As far as I can tell I have done everything correctly according to the docs.据我所知,我已根据文档正确完成所有操作。

Setting minifyEnabled & shrinkResources to false fixes it but why?将 minifyEnabled 和 shrinkResources 设置为 false 可以修复它,但为什么呢? I do not know.我不知道。 If somebody know please write a comment.如果有人知道请写评论。

buildTypes {       
    release {
        signingConfig signingConfigs.release
        minifyEnabled false
        shrinkResources false
    }
}

Recently Added Firebase最近添加的 Firebase

Depending on how your project is structured adding any new Firebase package might require a complete reset of the app on the device (deleting initial values):根据您的项目的结构,添加任何新的 Firebase package 可能需要在设备上完全重置应用程序(删除初始值):

  1. Uninstall the app from the device从设备上卸载应用程序
  2. Close and reopen Android Studio (sometimes optional)关闭并重新打开 Android Studio (有时可选)
  3. Run/Start the application again再次运行/启动应用程序

Done!完毕!

It's difficult to say exactly what's wrong without sifting through your entire project, but here are a few actions that will likely remedy the problem.如果不筛选整个项目,很难准确地说出哪里出了问题,但这里有一些可能会解决问题的措施。

  1. Run flutter doctor and verify everything is working as expected.运行flutter doctor并验证一切都按预期工作。
  2. Run flutter clean followed by flutter pub get .运行flutter clean然后flutter pub get

If you're still receiving the same error, then you likely made a mistake while editing one of the config files.如果您仍然收到相同的错误,那么您可能在编辑其中一个配置文件时犯了错误。

  1. Compare your android/app/main/AndroidManifest.xml to the previous working version (specifically ensure you didn't accidentally delete any <meta-data /> tags as doing so would result in said error.将您的 android/app/main/AndroidManifest.xml 与之前的工作版本进行比较(特别要确保您没有意外删除任何<meta-data />标签,因为这样做会导致上述错误。
  2. Do the same with the android/build.gradle and android/app/build.gradle.对 android/build.gradle 和 android/app/build.gradle 执行相同的操作。

What I ended up realizing after running into this issue, is that the error is super vague and doesn't necessarily mean there's a problem with firebase_core , rather there could be an issue with any of the Firebase plugins.遇到此问题后,我最终意识到,该错误非常模糊,并不一定意味着firebase_core存在问题,而是任何 Firebase 插件都可能存在问题。 So to narrow down where the issue was, I went through each firebase import individually and commented it out in the Pubspec.yaml file and ran it (along with commenting out all the code in my project that used that import), until I found which package was causing the issue.因此,为了缩小问题所在,我分别检查了每个 firebase 导入并在 Pubspec.yaml 文件中将其注释掉并运行它(同时注释掉我项目中使用该导入的所有代码),直到我发现package 导致了这个问题。

For me, I was experiencing the issue only when running on iOS.对我来说,我只在 iOS 上运行时遇到了这个问题。 It turned out that the firebase_messaging was the culprit and it was code that I had added to the iOS AppDelegate to handle the messaging that was no longer needed with the latest version of the firebase_messaging plugin.事实证明, firebase_messaging是罪魁祸首,它是我添加到 iOS AppDelegate 的代码,用于处理最新版本的firebase_messaging插件不再需要的消息传递。

I started a fresh project and made sure to change: classpath 'com.android.tools.build:gradle:4.2.0-alpha07' to the version officially supported: 3.5.0 Not sure if that downgrade was necessary because as I say, I restarted an entirely fresh project and something else may have effected it.我开始了一个新项目并确保更改: classpath 'com.android.tools.build:gradle:4.2.0-alpha07'到官方支持的版本: 3.5.0不确定是否需要降级,因为正如我所说,我重新启动了一个全新的项目,其他可能影响了它。

I also filed a ticket with Google which may prove helpful for anyone else in the future: https://github.com/FirebaseExtended/flutterfire/issues/3212#issuecomment-675407420我还向谷歌提交了一张票,这可能对未来的其他人有帮助: https://github.com/FirebaseExtended/flutterfire/issues/3212#issuecomment-675407420

To resolve this problem you have to implements this dependency for Android setup.要解决此问题,您必须为 Android 设置实现此依赖项。

firebase_core 

if you have this error for desktop application then you have to implement this dependency如果桌面应用程序出现此错误,则必须实现此依赖项

firebase_core_desktop: ^1.0.0

I did a bit of research on the issue and found an issue that was opened and closed with the agreed solution being to simply create a new flutter application and porting your dependencies and files one after the other.我对这个问题进行了一些研究,发现一个问题已经打开和关闭,商定的解决方案是简单地创建一个新的 flutter 应用程序并一个接一个地移植您的依赖项和文件。 While this was not a viable solution for me, running虽然这对我来说不是一个可行的解决方案,但运行

flutter clean

then然后

flutter pub get

seemed to fix the issue.似乎解决了这个问题。 As of yet I am unsure what package exactly causes the issue but on my deployment I had到目前为止,我不确定 package 究竟是什么导致了这个问题,但在我的部署中我有

google_sign_in: ^4.5.5
firebase_core: ^1.2.0
firebase_auth: ^1.2.0

only.只要。

I had the same problem I then reinstalled the app and updated my app level build.gradle我遇到了同样的问题,然后我重新安装了应用程序并更新了我的应用程序级别 build.gradle

defaultConfig{
// add the following line
 multiDexEnabled true
}

I had this issue.我有这个问题。 For me I forgot to create my project in firebase console properly, and i was trying to initialize my app like this, Firebase.initializeApp();对我来说,我忘记在 firebase 控制台中正确创建我的项目,我试图像这样初始化我的应用程序,Firebase.initializeApp();

FlutterFire includes instructions and tools for testing SignIn, Storage and Firestore: FlutterFire 包含用于测试 SignIn、Storage 和 Firestore 的说明和工具:

https://firebase.flutter.dev/docs/testing/testing/ https://firebase.flutter.dev/docs/testing/testing/

I had the same issue and above answers didn't helped that's why writing this.我有同样的问题,上面的答案没有帮助,这就是写这篇文章的原因。

Issue appeared when I changed my app's package name during development.当我在开发过程中更改应用程序的 package 名称时出现问题。 So I pulled the recent previous code from git and updated package name in that folder which solved the issue for me.因此,我从 git 中提取了最近的先前代码,并更新了该文件夹中的 package 名称,从而为我解决了这个问题。 Still don't know what might have caused this issue!仍然不知道是什么导致了这个问题!

Firebase.initializeApp() will throw error if you do not configure app with all the available platform.如果您未使用所有可用平台配置应用程序,Firebase.initializeApp() 将引发错误。

Use below line of code使用下面的代码行

WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
);

Follow these steps to remove this issue:-请按照以下步骤删除此问题:-

  1. do flutter cleanflutter clean
  2. then flutter pub cache repair然后flutter pub cache repair
  3. then flutter pub get然后flutter pub get
  4. Run your application运行您的应用程序

What fixed it for me was checking installing firebase_core.为我解决的问题是检查安装 firebase_core。 It was missing from my pubspec.yaml我的 pubspec.yaml 中缺少它

I faced this now, and will add the steps which fixed it for me.我现在面临这个问题,并将添加为我修复它的步骤。 I did NOT have to do a minifyEnabled false , or cut on any other performance.我不必执行minifyEnabled false或削减任何其他性能。 I can't say which steps were not needed, but hope this helps someone.我不能说不需要哪些步骤,但希望这对某人有所帮助。

  1. Bumped implementation platform('com.google.firebase:firebase-bom:30.3.2') in app/build.gradle file. app/build.gradle文件中implementation platform('com.google.firebase:firebase-bom:30.3.2') This forced me to bump compileSdkVersion to 33 as well in the same file.这迫使我在同一个文件中也将compileSdkVersion到 33。
  2. Bumped classpath 'com.android.tools.build:gradle:7.2.1 in android/build.gradle file.android/build.gradle文件中碰撞了classpath 'com.android.tools.build:gradle:7.2.1
  3. Bumped distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip in gradle-wrapper.properties在 gradle-wrapper.properties 中碰撞的distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
  4. After this I had to do a flutter pub upgrade --major-versions .在此之后,我必须执行flutter pub upgrade --major-versions
  5. Did a flutter clean on shell, and Invalidate and Restart on IDE.是否对 shell 进行了flutter clean ,并在 IDE 上Invalidate and Restart Even then I had some package conflict in firebase-messaging and firebase-auth, so I removed the versions from them in pubspec.yaml (just kept them as firebase_messaging: and firebase_auth: respt ).即便如此,我在 firebase-messaging 和 firebase-auth 中有一些 package 冲突,所以我在pubspec.yaml中删除了它们的版本(只是将它们保留为 firebase_messaging firebase_messaging:和 firebase_auth firebase_auth: respt )。 Voila, it started working!瞧,它开始工作了!

In my case, just follow the official documentations, first, run following command and install flutterfire_cli就我而言,只需按照官方文档进行操作,首先,运行以下命令并安装 flutterfire_cli

dart pub global activate flutterfire_cli

you may need install "Firebase CLI" too.您可能还需要安装“Firebase CLI”。 after installation, login to firebase, running安装后登录firebase,运行

firebase login

and finaly run,最后运行,

flutterfire configure

you can select the firebase project by menu and generate "firebase_options.dart" file.您可以通过菜单 select firebase 项目并生成“firebase_options.dart”文件。 in your project add following在您的项目中添加以下内容

import 'firebase_options.dart';
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(MyApp());
}

full document https://firebase.flutter.dev/docs/overview/完整文档https://firebase.flutter.dev/docs/overview/

暂无
暂无

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

相关问题 Flutter:MissingPluginException(找不到方法 DocumentReference#set on channel plugins.flutter.io/firebase_firestore 的实现) - Flutter: MissingPluginException(No implementation found for method DocumentReference#set on channel plugins.flutter.io/firebase_firestore) MissingPluginException(未找到方法 DocumentReference#get on channel plugins.flutter.io/firebase_firestore 的实现) - MissingPluginException(No implementation found for method DocumentReference#get on channel plugins.flutter.io/firebase_firestore) MissingPluginException(在频道 google_mlkit_image_labeler 上未找到方法 vision#startImageLabelDetector 的实现) - MissingPluginException(No implementation found for method vision#startImageLabelDetector on channel google_mlkit_image_labeler) 使用 Apple 登录 - 使用 Firebase 实现 Android - Sign in With Apple - Android Implementation with Firebase 找不到 com.google.android.gms.providerinstaller.dynamite 的本地模块描述符 class。 Flutter Firebase - Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found. Flutter Firebase Flutter Firebase 适用于真实设备 不适用于 Android 仿真器 - Flutter Firebase Works On Real Device Not On Android Emulator java.io.IOException: FIS_AUTH_ERROR in Android Z03548EZFF48D09214119934 - java.io.IOException: FIS_AUTH_ERROR in Android Firebase Firebase Auth 在 Flutter 中不起作用 - Firebase Auth not working in Flutter Firebase 通知为灰色 flutter - Firebase Notification is grey flutter Flutter firebase 未初始化 - Flutter firebase does not initialize
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM