{# This content gets published to the following location: #} {# https://firebase.google.com/docs/crashlytics/get-started?platform=flutter #}
This quickstart describes how to set up {{firebase_crashlytics}} in your app with the {{crashlytics}} Flutter plugin so that you can get comprehensive crash reports in the {{name_appmanager}}.
Setting up {{crashlytics}} involves using both a command-line tool and your IDE. To finish setup, you'll need to force a test exception to be thrown to send your first crash report to Firebase.
-
If you haven't already, configure and initialize Firebase in your Flutter project.
-
Recommended: To get features like crash-free users, breadcrumb logs, and velocity alerts, you need to enable {{firebase_analytics}} in your Firebase project.
All Android and Apple platforms supported by {{crashlytics}} (except watchOS) can take advantage of these features from {{firebase_analytics}}.
Make sure that {{firebase_analytics}} is enabled in your Firebase project: Go to settings > Project settings > Integrations tab, then follow the on-screen instructions for {{firebase_analytics}}.
-
From the root of your Flutter project, run the following command to install the {{crashlytics}} Flutter plugin:
flutter pub add firebase_crashlytics
-
From the root directory of your Flutter project, run the following command:
flutterfire configure
Running this command ensures that your Flutter app's Firebase configuration is up-to-date and, for Android, adds the required {{crashlytics}} Gradle plugin to your app.
-
Once complete, rebuild your Flutter project:
flutter run
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 "fatal" errors from the framework to Crashlytics
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
runApp(MyApp());
}
To catch asynchronous errors that aren't handled by the Flutter framework, use
PlatformDispatcher.instance.onError
:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
// Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
runApp(MyApp());
}
For examples of how to handle other types of errors, see Customize crash reports.
To finish setting up {{crashlytics}} and see initial data in the {{crashlytics}} dashboard of the {{name_appmanager}}, you need to force a test exception to be thrown.
<<_force-test-crash.md>>
If you've refreshed the console and you're still not seeing the test crash after five minutes, enable debug logging to see if your app is sending crash reports.
And that's it! {{crashlytics}} is now monitoring your app for crashes and, on Android, non-fatal errors and ANRs. Visit the [{{crashlytics}} dashboard](https://console.firebase.google.com/project/_/crashlytics){: .external} to view and investigate all your reports and statistics.
-
Customize your crash report setup by adding opt-in reporting, logs, keys, and tracking of additional non-fatal errors.
-
Integrate with {{play_name}} so that you can filter your Android app's crash reports by {{play_name}} track directly in the {{crashlytics}} dashboard. This allows you to better focus your dashboard on specific builds.
-
View stack traces and crash statistics alongside your code{: .external} with the App Quality Insights window in Android Studio (available starting with Electric Eel 2022.1.1).