Skip to content
Back to archipelago.banuacoder.com

Monitoring Implementations

How to add Firebase Crashlytics to a Flutter app with monitoring_sdk ​

Free Reference for crashlytics_monitoring_impl: every variable, option and package it generates. Command: archipelago generate crashlytics_monitoring_impl

Generate the Crashlytics vendor, add Firebase credentials on Android and iOS, see how Flutter errors reach Crashlytics, and control collection with consent.

What you'll learn ​

  • Generating the Crashlytics monitoring implementation brick
  • Adding Firebase credentials on Android and iOS
  • Seeing how Flutter errors reach Crashlytics
  • Controlling collection with consent

Prerequisites ​

  • monitoring_sdk generated first (see Monitoring SDK)
  • A Firebase project with Crashlytics enabled
  • Firebase configured with flutterfire configure (see Firebase setup)

Step 1: Generate the Brick ​

Skip this step if you chose crashlytics in monitoringVendors at project creation.

bash
archipelago generate crashlytics_monitoring_impl

The prompts are:

  • appName: your app name, for example MyApp
  • isForMonorepo: leave this as true

The brick creates infrastructure/crashlytics_monitoring_impl/. It also adds a guarded Firebase.initializeApp() to bootstrap.dart before initializeInjector(). Without Firebase config, the app still boots and this vendor is skipped with a debug message.

Step 2: Add Firebase Credential Files ​

flutterfire configure writes these. Or download them from the Firebase console and place them by hand:

  • Android: apps/<appName>/android/app/google-services.json
  • iOS: apps/<appName>/ios/Runner/GoogleService-Info.plist

Apply the Google Services and Crashlytics Gradle plugins on Android. Then enable Crashlytics in the Firebase console under Crashlytics, then Get started.

Step 3: Check the Registration ​

You register nothing by hand. The post-generation hook adds the package to the host app pubspec.yaml. It registers CrashlyticsMonitoringImplPackageModule in lib/di/injector.dart.

The monitoring_impl fanout builds its vendor list when AppMonitoring is first resolved. Every vendor module must run before that. Install order does not decide the injector order. The hook rebuilds the entries from the package manifests in dependency order.

The vendor registers as an AppMonitoringVendor named MonitoringInjectorKey.crashlytics. If Firebase is not configured, FirebaseCrashlytics.instance throws when DI builds the vendor. The fanout skips that vendor and logs a debug message.

Step 4: Know How Errors Reach Crashlytics ​

You write no error handler. The generated bootstrap.dart owns FlutterError.onError and PlatformDispatcher.instance.onError. It reports through getIt<AppMonitoring>().

Crashlytics implements FlutterAwareMonitoringVendor. Flutter framework errors go to its dedicated recordFlutterError API, which keeps the widget-tree information. Do not install your own handler. It replaces the one in bootstrap.dart and skips the consent gate.

AppMonitoring sends nothing to any vendor until ConsentPurpose.diagnostics is granted. It starts the vendors when consent flips to granted.

The vendor itself has no enable argument:

  • initialize() calls setCrashlyticsCollectionEnabled(true).
  • dispose() calls setCrashlyticsCollectionEnabled(false).
  • When diagnostics consent is withdrawn, the vendor also calls deleteUnsentReports() and clears the user id, so reports stored on the device are never uploaded.

Crashlytics has no transaction concept. recordTransaction runs your action and returns its result. Pair Crashlytics with Sentry or Grafana if you need spans.

Step 6: Verify in Firebase Console ​

Grant diagnostics consent, then run a release build. Trigger a test crash:

dart
FirebaseCrashlytics.instance.crash();

Within a few minutes the crash appears in Firebase Console, then Crashlytics. Log lines sent with monitoring.log(message: '...', tag: 'Auth') show as [Auth] message in the log tab.

Next Steps ​