Skip to content

Firebase Crashlytics Monitoring Implementation

What you'll learn

  • Generating the Crashlytics monitoring implementation brick
  • Wiring Firebase credentials on Android and iOS
  • Registering the impl in DI and hooking Flutter error capture

Prerequisites

  • monitoring_sdk already generated (see Monitoring SDK)
  • A Firebase project with Crashlytics enabled
  • google-services Gradle plugin applied in your Android app

Step 1: Generate the Brick

bash
archipelago generate crashlytics_monitoring_impl

You will be prompted for:

  • appName — must match your monorepo app name (e.g. MyApp)
  • isForMonorepotrue

The brick generates in infrastructure/crashlytics_monitoring_impl/.

Step 2: Add Firebase Credential Files

Download the credential files from your Firebase project console and place them in the correct locations:

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

Then enable Crashlytics in the Firebase console under Crashlytics → Get started.

Confirm the google-services plugin is applied in android/app/build.gradle:

groovy
apply plugin: 'com.google.firebase.crashlytics'

Step 3: Import the Package Module in Your App DI

The brick registers itself via @InjectableInit.microPackage(). Add the module import in your host app's DI setup:

dart
// apps/<appName>/lib/di/app_module.dart
import 'package:crashlytics_monitoring_impl/crashlytics_monitoring_impl.dart';

@InjectableInit(
  initializerName: 'configureDependencies',
  microPackages: [
    CrashlyticsMonitoringImplPackageModule(),
  ],
)
Future<void> configureDependencies() => getIt.init();

The impl is registered as a @LazySingleton named MonitoringInjectorKey.crashlyticsImpl.

Step 4: Hook Flutter Error Capture

Wire Crashlytics into Flutter's global error handler in your main.dart, after DI is configured:

dart
FlutterError.onError = (details) {
  getIt<AppMonitoring>(instanceName: MonitoringInjectorKey.crashlyticsImpl)
      .recordFlutterError(details);
};

For consent-aware collection, pass the user's preference to initialize:

dart
await getIt<AppMonitoring>(instanceName: MonitoringInjectorKey.crashlyticsImpl)
    .initialize(enable: userConsentGranted);

Setting enable: false calls setCrashlyticsCollectionEnabled(false) — no data is sent until the user opts in.

Step 5: Verify in Firebase Console

Run a release build and trigger a test crash:

dart
FirebaseCrashlytics.instance.crash();

Within a few minutes, the crash should appear in Firebase Console → Crashlytics. Custom logs sent via monitoring.log(message: '...', tag: 'Auth') appear as [Auth] message in the Crashlytics log tab.

Next Steps

Built by Banua Coder