Flutter crashlytics integration

First, set up a Firebase project

Config firebase_crashlytics


  • Update dependencies
  firebase_crashlytics: ^0.1.3+3
  • Install it via pub get

Android integration

  • Update android/build.gradle
buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        maven {
            url 'https://maven.fabric.io/public'

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.fabric.tools:gradle:1.26.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  • Update android/app/build.gradle. Place 2 lines at the bottom of the file
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

iOS integration

  • Open ios/Runner.xcworkspace
  • Select Runner from the project navigation
  • Select the Build Phases tab.
  • Click + Add a new build phase, and select New Run Script Phase.
  • Add command below to the Type a script... text box.

Use the plugin

import 'dart:async';

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:nft/my_app.dart';
import 'package:nft/utils/app_config.dart';

void main() async {
  // Init dev config
  Config(environment: Env.dev());

  // Initialize Crash report
  Crashlytics.instance.enableInDevMode = true;
  // Pass all uncaught errors to Crashlytics.
  FlutterError.onError = Crashlytics.instance.recordFlutterError;

  runZoned(() async {
    await myMain();
  }, onError: Crashlytics.instance.recordError);

To test crash, just create a new button and send test crashing

  child: const Text('Crash'),
  onPressed: () {
    // Use Crashlytics to throw an error. Use this for
    // confirmation that errors are being correctly reported.
  • Run the app and wait for Firebase collects data, it may take a few hours.
  • Open Firebase console, Quality -> Crashlytics

More example: https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_crashlytics/example/lib/main.dart




Leave a Reply

Your email address will not be published.Required fields are marked *