当我运行我的应用程序时遇到此错误。我将 google-services.json 下载到我的 android/app 文件夹中。我已放入
apply plugin: 'com.google.gms.google-services'
进入我的 app/build.gradle 文件。最初我没有添加“应用插件”,所以我后来添加了它,但似乎没有什么区别。我也把我的
classpath '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):
pubspec,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"
}
}
应用程序/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 干净 - 我试过了 flutter 获取包 - 我尝试过 flutter doctor -v - 我试过了
最佳答案
感谢@Nishuthan S 为我发布了解决方案。正如您可以在评论中看到他的建议。
尝试flutter create。然后flutter clean然后flutter run如果这不起作用,您可以尝试备份lib文件夹并pubspec删除项目创建一个新项目在相同的包名称中并替换 lib 和 pubspec –
在我按照他的建议进行操作后,我将图像、字体和声音读回到新项目中。我输入 flutter pub get 来检查 pubspec.yaml 是否正常工作。我将 firebase 中的依赖项读取到正确的文件中,这可以根据您自己的项目在他们的网站上找到。现在该项目正在运作。感谢大家的帮助
关于Firebase 尚未正确初始化。您是否已将 "google-services.json"文件添加到项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66991781/