Flutterfire: [📚] [Firebase Crashlytics] Handling uncaught errors

Created on 22 Sep 2020  Â·  4Comments  Â·  Source: FirebaseExtended/flutterfire

The guidance here is no longer compatible with Firebase Crashlytics 0.2.0 because the FirebaseApp must first be initialized -- you get this exception:

[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
#0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:118:5)
#1      Firebase.app (package:firebase_core/src/firebase.dart:52:41)
#2      FirebaseCrashlytics.instance (package:firebase_crashlytics/src/firebase_crashlytics.dart:31:62)
#3      main (package:kozzeter/main.dart:21:46)
#4      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:233:25)
#5      _rootRun (dart:async/zone.dart:1190:13)
#6      _CustomZone.run (dart:async/zone.dart:1093:19)
#7      _runZoned (dart:async/zone.dart:1630:10)
#8      runZonedGuarded (dart:async/zone.dart:1618:12)
#9      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:225:5)
#10     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch<…>
good first issue crashlytics documentation

Most helpful comment

For the record, I was able to get this to work. The purpose of this issue is to ensure that the documentation gets updated.

All 4 comments

You also get this exception when trying to use FirebaseCrashlytics.instance.log() before Firebase.initializeApp() was called.

And you really have to await the Firebase.initializeApp() before being able to call FirebaseCrashlytics.instance.log().

You might want to run Firebase.initializeApp() in your main():
https://github.com/FirebaseExtended/flutterfire/issues/3271#issuecomment-677703143

Can confirm that adding Firebase.initializeApp() to main() works

You may also see an exception like this when you make main() an async function:

Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.

Add the method call WidgetsFlutterBinding.ensureInitialized(); to your main can solve this

Your main() will look something like:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp();

  runZonedGuarded(() => runApp(new App()), FirebaseCrashlytics.instance.recordError);
}

For the record, I was able to get this to work. The purpose of this issue is to ensure that the documentation gets updated.

Was this page helpful?
0 / 5 - 0 ratings