Using Firebase Crashlytics with Flutter

This tutorial explains how to set up Firebase Crashlytics in your app with the Crashlytics Flutter plugin so that you can get comprehensive crash reports in the Firebase console.

create firebase project

before leaving visit console from the window that opens Add project Click the button to create a Firabase project.

Make sure the Google Analytics field is selected

picture description

picture description

picture description

npm ile firebase cli krun
(This step is required for the Flutterfire command to run.)

npm install -g firebase-tools

Sign in to Firebase using your Google Account:

Login to Firebase using your Google Account by running the following command:

firebase login

picture description

List your Firebase projects to check if the CLI is loaded properly and your account is being accessed. Run the following command:

firebase projects:list

FlutterFire CLI’yi kurun
Install FlutterFire CLI by running the following command from any directory:

dart pub global activate flutterfire_cli

Add alert path to path field in your environment variable

pattern:
picture description

Add Crashlytics to Your Flutter Project

To install the Crashlytics Flutter plugin, run the following command in the path of your Flutter project after running your terminal as administrator:

flutter pub add firebase_crashlytics

flutterfire configure

Running this command ensures that the Firebase configuration of your Flutter app is up to date and adds the required Crashlytics Gradle plugin for Android to your app.

flutterfire configure After running the command, select the firebase project you have created as below and press enter.

picture description

Finally, select the platform and press Enter (Android and iOS will be selected, you can proceed by pressing the Enter key.)

picture description

At the end of this process, two different App IDs are created for Android and iOS.

picture description

Add the following lines to your android\build.gradle file as in the picture

 // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.10'
        // END: FlutterFire Configuration
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
enter fullscreen mode

exit fullscreen mode

picture description

Add the following lines to your android\app\build.gradle file as shown in the picture

picture description


// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

dependencies {
   ...
}
}

apply plugin: 'com.google.firebase.crashlytics'
enter fullscreen mode

exit fullscreen mode

Once done, run your Flutter project:

flutter run

Your firebase project should look like the picture

picture description

(Optional) If your Flutter project uses the –split-debug-info flag (and optionally the –obfuscate flag), you will need to use the Firebase CLI (v.11.9.0+) to load Android symbols. should be used.

Run the following command from the root of your flutter project:

firebase crashlytics:symbols:upload --app=APP_ID PATH/TO/symbols

PATH/TO/symbols The directory is the same directory that you pass in the –split-debug-info flag when you build the application.

Configure crash handler

You can automatically catch any errors that occur within the Flutter framework by overriding FlutterError.onError with FirebaseCrashlytics.instance.recordFlutterFatalError :

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

  await Firebase.initializeApp();

  // Pass all uncaught errors from the framework to Crashlytics.
  FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;

  runApp(MyApp());
}
enter fullscreen mode

exit fullscreen mode

return error to test installation

TextButton(
    onPressed: () => throw Exception(),
    child: const Text("Throw Test Exception"),
),
enter fullscreen mode

exit fullscreen mode

Run your application.

Click on the Throw Test Exception button you added to submit the first report of your application:

To see your test crash, go to the Crashlytics dashboard in the Firebase console.

picture description

If you’ve refreshed the console and after five minutes the test crash doesn’t appear, enable debug logging to see if your app is sending crash reports.

Resource:
firebase cli range
Add Firebase to your app
crashlytics
flutter-not-recognized
https://firebase.google.com/docs/crashlytics

Leave a Comment