【问题标题】:Firebase has not been correctly initialized. Have you added the "google-services.json" file to the projectFirebase 尚未正确初始化。您是否将“google-services.json”文件添加到项目中
【发布时间】:2021-07-03 14:28:11
【问题描述】:

我在运行我的应用程序时收到此错误。我将 google-services.json 下载到我的 android/app 文件夹中。我已经放了

应用插件:'com.google.gms.google-services'

进入我的 app/build.gradle 文件。最初我没有放入“应用插件”,所以我稍后放入它似乎并没有什么不同。我也把我的

类路径'com.google.gms:google-services:4.3.5'

into my android/build.gradle. The entire error when i run the app is



E/flutter ( 4213): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 
[core/not-initialized] Firebase has not been correctly initialized. 
Have you added the 
"google-services.json" file to the project? 
E/flutter ( 4213):     
E/flutter ( 4213): View the Android Installation documentation for more information: 
https://firebase.flutter.dev/docs/installation/android
E/flutter ( 4213): 
E/flutter ( 4213): #0      MethodChannelFirebase.initializeApp 
(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:88:9)
E/flutter ( 4213): <asynchronous suspension>

E/flutter ( 4213): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)

E/flutter ( 4213): <asynchronous suspension>

E/flutter ( 4213): #2     
 main (package:rider_app/main.dart:12:3)
E/flutter ( 4213): <asynchronous suspension>
E/flutter ( 4213): 

(编辑:我看到了我可能没有看到的更多错误,我希望你们能理解它们)

Launching lib\main.dart on Android SDK built for x86 in debug mode...

Running Gradle task 'assembleDebug'...

Note: "path"\flutter_windows_2.0.4-stable\.pub-cache\hosted\pub.dartlang.org
\firebase_core-1.0.3\android\src\main\java\io\flutter\plugins\firebase
\core\FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: "path"\flutter_windows_2.0.4-stable\.pub-cache\hosted\pub.dartlang.org
\firebase_auth-1.0.2\android\src\main\java\io\flutter\plugins\firebase
\auth\FlutterFirebaseAuthPlugin.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

√ 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:55393/AAigea5LZbA=/ws

Syncing files to device Android SDK built for x86...

D/EGL_emulation( 8043): eglMakeCurrent: 0x9c861020: ver 2 0 (tinfo 
0xaa003f90)

E/flutter ( 8043): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled 
Exception: [core/not-initialized] Firebase has not been correctly 
initialized. Have you added the "google-services.json" file to the project? 

E/flutter ( 8043):     

E/flutter ( 8043): View the Android Installation documentation for more 
information: https://firebase.flutter.dev/docs/installation/android

E/flutter ( 8043): 

E/flutter ( 8043): #0      MethodChannelFirebase.initializeApp 
(package:firebase_core_platform_interface/src/method_channel
/method_channel_firebase.dart:88:9)

E/flutter ( 8043): <asynchronous suspension>

E/flutter ( 8043): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:41:31)
E/flutter ( 8043): <asynchronous suspension>
E/flutter ( 8043): #2      main (package:riderapp/main.dart:14:3)
E/flutter ( 8043): <asynchronous suspension>
E/flutter ( 8043): 

发布规范,yaml

  cupertino_icons: ^1.0.2
  firebase_core: ^1.0.3
  firebase_auth: ^1.0.2
  firebase_database: ^6.1.2
  fluttertoast: ^8.0.3

gradle/build.gradle

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.3.5'
        classpath "org.jetbrains.kotlin:kotlin-gradle-                                                                                   plugin:$kotlin_version"
    }
}

app/build.gradle

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// this is incase i get error archives can't exceed 64k
implementation 'com.android.support:multidex:1.0.3'
}

//apply plugin:
apply plugin: 'com.google.gms.google-services'

flutter clean - 我试过了 颤振获取包裹 - 我试过了 颤振医生 -v - 我试过了

【问题讨论】:

    标签: firebase flutter


    【解决方案1】:

    感谢@Nishuthan S 为我发布解决方案。正如您在 cmets 中看到的他的建议。

    尝试 flutter create 。然后 flutter clean 然后 flutter run 如果这不起作用,您可以尝试备份您的 lib 文件夹并 pubspec 删除项目 创建一个新项目在相同的包名中并替换 lib 和 pubspec

    按照他的建议完成后,我将图像、字体和声音读回新项目。我输入了 flutter pub get 来检查 pubspec.yaml 是否正常工作。我将 firebase 的依赖项读入了正确的文件,这可以在他们的网站上找到,具体取决于您自己的项目。现在该项目正在运行。感谢大家的帮助

    【讨论】:

      【解决方案2】:

      在你的主函数中添加await Firebase.initializeApp();

      例子:

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

      firebase_core: ^1.0.3https://pub.dev/packages/firebase_core

      【讨论】:

      • 感谢您的回复,我已经添加了,但我仍然遇到同样的错误。
      • @BlankCoder 你试过flutter clean 吗?
      • 嗨 Nishuthan,我尝试了“flutter clearn”,然后尝试了“flutter pub get”。我遇到了同样的错误。奇怪的是,在我收到错误之前,应用程序会在模拟器上以白屏的形式加载,就像它几乎已经加载但最终停止工作一样
      • @BlankCoder 你用的是什么firebase包,你能分享一些代码吗?
      • 我已经添加了代码,我编辑了消息并在底部添加了代码。我发现它的可读性不是很好,所以会再次编辑,直到它可读为止。
      猜你喜欢
      • 1970-01-01
      • 2021-06-08
      • 2017-06-08
      • 2022-01-22
      • 1970-01-01
      • 2014-06-05
      • 2022-06-18
      • 1970-01-01
      相关资源
      最近更新 更多