E/flutter ( 6571): [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(6571):在io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)E/flutter(6571):在 io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda2.run(来源未知:4)E/flutter(6571):在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)E/flutter (6571):在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)E/flutter(6571):在java.lang.Thread.run(Thread.java:1012)E/flutter(6571) ):,空)E/flutter(6571):#0 FirebaseCoreHostApi.optionsFromResource(包:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)E/flutter(6571):E/flutter(6571): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25) E/flutter ( 6571): E/flutter ( 6571): #2 Firebase.initializeApp (package:firebase_core/src/firebase.飞镖:43:31)

调用后立即抛出错误 await Firebase.initializeApp();

它是在删除已弃用的Flutter Gradle 插件的命令式应用后发生的。 IE。迁移到新的后,声明性应用问题开始了。通过创建也面临相同问题

*为 ios 和 android 而不是 web 环境构建应用程序:
firebase_core: ^2.27.1

任何解决此问题的帮助将不胜感激。谢谢


1 个回答
1

经过一番研究和努力,我发现在通过options其工作后,

 await Firebase.initializeApp(
      options: FirebaseOptions(
    apiKey: 'key',
    appId: 'id',
    messagingSenderId: 'sendid',
    projectId: 'myapp',
    storageBucket: 'myapp-b9yt18.appspot.com',
  )
    );

创建了新的应用程序,并使用 cli 模式对其进行配置,它将生成适用于所有平台的选项文件。从flutte 3.19开始,仅仅添加google-services.json似乎还不够

祝你好运。

生成文件后,您的 firebaseinit 代码应该看起来像此选项是根据平台通过 CLI 生成的选项文件应用的

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

如果有帮助的话考虑点赞:)

0