Flutter Firebase _性能包:默认FirebaseApp未在此进程中初始化

bxgwgixi  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(114)

我已经在我的flutter项目中添加了firebase_performance包。但是当运行项目时,它在构建后存在,显示错误Default FirebaseApp is not initialized in this process。但是我已经在main.dart文件中添加了代码Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);

Installing build/app/outputs/flutter-apk/app.apk...                 5.8s
E/AndroidRuntime(23097): FATAL EXCEPTION: main
E/AndroidRuntime(23097): Process: com.example.demo_app, PID: 23097
E/AndroidRuntime(23097): java.lang.RuntimeException: Unable to resume activity {com.example.demo_app/com.example.demo_app.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.demo_app. Make sure to call FirebaseApp.initializeApp(Context) first.
E/AndroidRuntime(23097):        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4884)
E/AndroidRuntime(23097):        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4922)
E/AndroidRuntime(23097):        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
E/AndroidRuntime(23097):        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
E/AndroidRuntime(23097):        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
E/AndroidRuntime(23097):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2414)
E/AndroidRuntime(23097):        at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(23097):        at android.os.Looper.loop(Looper.java:265)
E/AndroidRuntime(23097):        at android.app.ActivityThread.main(ActivityThread.java:8360)
E/AndroidRuntime(23097):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23097):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
E/AndroidRuntime(23097):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
E/AndroidRuntime(23097): Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.demo_app. Make sure to call FirebaseApp.initializeApp(Context) first.
E/AndroidRuntime(23097):        at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:186)
E/AndroidRuntime(23097):        at com.google.firebase.perf.FirebasePerformance.getInstance(FirebasePerformance.java:132)
E/AndroidRuntime(23097):        at com.google.firebase.perf.FirebasePerformanceInitializer.onAppColdStart(FirebasePerformanceInitializer.java:29)
E/AndroidRuntime(23097):        at com.google.firebase.perf.application.AppStateMonitor.sendAppColdStartUpdate(AppStateMonitor.java:322)
E/AndroidRuntime(23097):        at com.google.firebase.perf.application.AppStateMonitor.onActivityResumed(AppStateMonitor.java:240)
E/AndroidRuntime(23097):        at android.app.Application.dispatchActivityResumed(Application.java:451)
E/AndroidRuntime(23097):        at android.app.Activity.dispatchActivityResumed(Activity.java:1437)
E/AndroidRuntime(23097):        at android.app.Activity.onResume(Activity.java:1967)
E/AndroidRuntime(23097):        at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:310)
E/AndroidRuntime(23097):        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1463)
E/AndroidRuntime(23097):        at android.app.Activity.performResume(Activity.java:8294)
E/AndroidRuntime(23097):        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4874)
E/AndroidRuntime(23097):        ... 11 more
zzoitvuj

zzoitvuj1#

你的main.dart文件是什么样子的?当我第一次开始使用FireBase时,我经常忘记把main函数设置为异步的。假设你已经配置了FireBase的所有内容,你的main应该是这样的:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

如果你已经这么做了就告诉我。

相关问题