Skip to main content

firebase_crashlytics

PackageKindProvides the roleNeedsChoose with
smf_firebase_crashlyticsinfrastructureCrash reportingfirebase_core-m firebase_crashlytics

firebase_crashlytics reports errors to Firebase Crashlytics with the firebase_crashlytics package: the errors that the app does not handle, and those that its code reports.

What it adds to the app​

The module adds firebase_crashlytics: ^5.4.0 to the dependencies, and lib/core/crash_reporting/crashlytics_crash_reporter.dart with the reporter on FirebaseCrashlytics.instance.

Whichever module provides it, the crash reporting role adds lib/core/crash_reporting/crash_reporter.dart with:

  • the CrashReporter interface, where recordError and recordFlutterError report an error, log adds a message to the log sent with the next report, and setUserId sets the id of the signed-in user or clears it with null;
  • createCrashReporter(), which returns the reporter of the app, a reporter that forwards every call to the reporters of all the modules that provide crash reporting, so an app can report to more than one service;
  • installCrashReporting(), which reports as fatal the errors of the main isolate that the app does not handle.

In its platform phase, bootstrap() initializes Firebase and then calls installCrashReporting().

What gets reported and printed​

  • Flutter still presents an error that it catches, such as one in a build, as it does by default, in every mode. The reporter sends the same report that recordFlutterError of Crashlytics sends.
  • Any other uncaught error goes to recordError, and in debug mode the engine still prints it.
  • The reporter itself prints nothing, so an error that the code of the app reports is not printed either.
  • setUserId(null) clears the id of the user by setting an empty one, as Crashlytics does.

The handlers cover the main isolate. For errors of other isolates, see Services and state.

Getting the reporter​

The reporter is created on first use, without waiting. With a module of dependency injection, the role registers it in the container as a lazy singleton, and a feature takes it with resolve in its composition file. Without a container, the code of the app calls createCrashReporter().

Native setup​

The module adds nothing to the native projects itself. flutterfire configure, which firebase_core runs after generation, adds what Crashlytics needs to an app that depends on firebase_crashlytics, such as the build phase that uploads the debug symbols on macOS. For that phase and flutter build ipa, see Firebase.

Choosing it​

smf create asks which modules provide the crash reporting of the app, and the answer may be none. To choose it without the question, name it in -m, and firebase_core comes with it:

smf create my_app -m firebase_crashlytics