[应用程序/build.gradle] (https://i.sstatic.net/xFBEUbUi.png)
[主.dart] (https://i.sstatic.net/ARYitV8J.png)
E/flutter ( 4746): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., Exception, Cause: null, Stacktrace: java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
E/flutter ( 4746): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)
E/flutter ( 4746): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda2.run(Unknown Source:4)
E/flutter ( 4746): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/flutter ( 4746): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/flutter ( 4746): at java.lang.Thread.run(Thread.java:923)
E/flutter ( 4746): , null)
E/flutter ( 4746): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter ( 4746): <asynchronous suspension>
E/flutter ( 4746): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 4746): <asynchronous suspension>
E/flutter ( 4746): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 4746): <asynchronous suspension>
E/flutter ( 4746): #3 main (package:new_hemobridge/main.dart:7:2)
E/flutter ( 4746): <asynchronous suspension>
E/flutter ( 4746):
Syncing files to device sdk gphone x86... 709ms
Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on sdk gphone x86 is available at: http://127.0.0.1:63008/v8-J0gdc5eg=/
The Flutter DevTools debugger and profiler on sdk gphone x86 is available at:
http://127.0.0.1:9102?uri=http://127.0.0.1:63008/v8-J0gdc5eg=/
i dont know,everyone suggest check the google service json file but its all right,doublechecked the dependencies and pubsec,yaml file nothing sus caught my eyes .
我不知道,每个人都建议检查谷歌服务json文件,但它没问题,仔细检查了依赖项和pubsec,yaml文件没有什么引起我的注意
您必须添加
options: DefaultFirebaseOptions.currentPlatform,
作为 Firebase.initializeApp
的属性
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
为此,您需要
firebase_options.dart
文件
以下是我将 Firebase 添加到环境并将其与 flutter 链接的方法:
按照此FlutterFire中的说明进行操作,以便我可以将 firebase 项目与 flutter 项目链接起来
之后运行应用程序以确保一切正常。
我需要
firebase_CLI
将 firebase_options.dart
文件添加到项目中,以便我可以在 DefaultFirebaseOptions.currentPlatform
中使用
main.dart
我从
here下载了
CLI
并安装了它(您可以直接使用 Gmail 登录您的 Firebase 项目)。
我从
这里下载了最新版本的
node.js
安装起来估计需要一段时间
powerShell
确保这三个路径添加到
system variables
&& personal variables
C:\Users\USERNAME\AppData\Local\Pub\Cache\bin
C:\Users\USERNAME\AppData\Roaming\npm
C:\Program Files\nodejs
运行
node --version
&& npm --version
以确保一切正常
在命令提示符下运行
npm install -g firebase-tools
然后
dart pub global activate flutterfire_cli
如果
vsCode
打开,请将其关闭并再次打开
在
vsCode
中的flutter项目目录中运行flutterfire configure
您还可以阅读这些说明
它应该可以运行并且一切正常。