Using Firebase Crashlytics with Flutter
Published: 2022-11-06 12:53:56

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

Create a Firebase project

Create a firebase project by going to [Firebase Crashlytics](https://firebase.google.com/products/crashlytics?gclid=Cj0KCQjwwfiaBhC7ARIsAGvcPe7XDPT9OV_-Ia1CqqXSm2kewlKJ2dnGAUXfj7jte1WW1HPEOZ_mvTQaAqOCEALw_wcB&gclsrc=aw.ds), first going to the `visit console`, and then clicking the `Add project` button from the window that opens.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jroaqcvbviccc66u723p.png)

**Make sure that the Google Analytics field is selected**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qf113zfmxw8bfrzbi2kj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8lmhzlc0pkmnu68wzbh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7bqdwatjcwf5i5j0v5q.png)

install Firebase CLI with npm

(this step is necessary to be able to execute the flutterfire command.)

`npm install -g firebase-tools`

Log in to Firebase using your Google account:

Log in to Firebase using your Google account by running the command below:

firebase login


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0dal64bgvxax7m8h0c9.png)


By listing your Firebase projects, test whether the CLI is installed properly and your account is accessed. Run the following command:

`firebase projects:list`

**Install FlutterFire CLI**
Install FlutterFire CLI by running the following command from any directory:

`dart pub global activate flutterfire_cli`

Add the path that appears in the warning to the path field in your environment variables

example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uivsv1tww2tis9p1wbv.png)


**Add Crashlytics to your Flutter project**

To install the Crashlytics Flutter plugin, run the following commands on the path where your flutter project is located after running your terminal as an administrator:

`flutter pub add firebase_crashlytics`

`flutterfire configure`

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

After running the `flutterfire configure` command, press enter by selecting the firebase project you created as follows.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3x4razwuyfzw1n4se9t.png)

Finally, press enter by selecting the platform (android and iOS will be selected, you can proceed by pressing enter.)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3zzzzv4rvoap8k6xg4y.png)

At the end of this process, two different app IDs for android and iOS are formed.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i04a4ptlplz3el3z1x9.png)

android\build.gradle the following lines to your gradle file as pictured

```
 // 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'
```



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwe03ouu2t8v3u2w6744.png)

android\app\build.add the following lines to your gradle file as pictured



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j8g3pw7gcuw6u21ppjzs.png)


```
// 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'
```


Once completed, run your Flutter project:

`flutter run`


**Your Firebase project should look like the one pictured**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dc3jiob881q7m0tmjqbh.png)

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

From the root directory of your Flutter project, run the following command:

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

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

Note: Support for --split-debug-info is currently only available on Android.
For Apple platforms, support for this feature will be available in an upcoming release, but you can access it now by using the master channel of the Flutter SDK.

**Configure crash handlers**

You can automatically catch all errors that are thrown 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());
}
```


Return an error to test the installation:

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

Run your application.

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

To see your test crash, go to the Firebase console's Crashlytics [dashboard](https://console.firebase.google.com/u/0/project/_/crashlytics).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tp0oszlq7rs0q2emqe05.png)

If you've refreshed the console and you're still not seeing the test crash after five minutes, [enable debug logging](https://firebase.google.com/docs/crashlytics/test-implementation?platform=flutter#enable-debug-logging) to see if your app is sending crash reports.

Resources
[Firebase CLI kurun](https://firebase.google.com/docs/cli#setup_update_cli)
[Firebase'i uygulamanıza ekleyin](https://firebase.google.com/docs/flutter/setup?platform=ios
)
[crashlytics](https://firebase.google.com/products/crashlytics?gclid=Cj0KCQjwwfiaBhC7ARIsAGvcPe7XDPT9OV_-Ia1CqqXSm2kewlKJ2dnGAUXfj7jte1WW1HPEOZ_mvTQaAqOCEALw_wcB&gclsrc=aw.ds)
[flutterfire-is-not-recognized](https://stackoverflow-com.translate.goog/questions/70320263/the-term-flutterfire-is-not-recognized-as-the-name-of-a-cmdlet-function-scri?_x_tr_sl=en&_x_tr_tl=tr&_x_tr_hl=tr&_x_tr_pto=sc)
https://firebase.google.com/docs/crashlytics