firebase_crashlytics 0.1.3+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

firebase_crashlytics plugin #

A Flutter plugin to use the Firebase Crashlytics Service.

pub package

For Flutter plugins for other Firebase products, see README.md.

Usage #

Import the firebase_crashlytics plugin #

To use the firebase_crashlytics plugin, follow the plugin installation instructions.

Android integration #

Enable the Google services by configuring the Gradle scripts as such:

  1. Add the Fabric repository to the [project]/android/build.gradle file.
repositories {
  google()
  jcenter()
  // Additional repository for fabric resources
  maven {
    url 'https://maven.fabric.io/public'
  }
}
  1. Add the following classpaths to the [project]/android/build.gradle file.
dependencies {
  // Example existing classpath
  classpath 'com.android.tools.build:gradle:3.2.1'
  // Add the google services classpath
  classpath 'com.google.gms:google-services:4.3.0'
  // Add fabric classpath
  classpath 'io.fabric.tools:gradle:1.26.1'
}
  1. Apply the following plugins in the [project]/android/app/build.gradle file.
// ADD THIS AT THE BOTTOM
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

Note: If this section is not completed, you will get an error like this:

java.lang.IllegalStateException:
Default FirebaseApp is not initialized in this process [package name].
Make sure to call FirebaseApp.initializeApp(Context) first.

Note: When you are debugging on Android, use a device or AVD with Google Play services. Otherwise, you will not be able to use Firebase Crashlytics.

iOS Integration #

Add the Crashlytics run scripts:

  1. From Xcode select Runner from the project navigation.
  2. Select the Build Phases tab.
  3. Click + Add a new build phase, and select New Run Script Phase.
  4. Add ${PODS_ROOT}/Fabric/run to the Type a script... text box.
  5. If you are using Xcode 10, add the location of Info.plist, built by your app, to the Build Phase's Input Files field.
    E.g.: $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)

Use the plugin #

Add the following imports to your Dart code:

import 'package:firebase_crashlytics/firebase_crashlytics.dart';

Setup Crashlytics:

void main() {
  // Set `enableInDevMode` to true to see reports while in debug mode
  // This is only to be used for confirming that reports are being
  // submitted as expected. It is not intended to be used for everyday
  // development.
  Crashlytics.instance.enableInDevMode = true;

  // Pass all uncaught errors from the framework to Crashlytics.
  FlutterError.onError = Crashlytics.instance.recordFlutterError;
  
  runApp(MyApp());
}

Overriding FlutterError.onError with Crashlytics.instance.recordFlutterError will automatically catch all errors that are thrown from within the Flutter framework.
If you want to catch errors that occur in runZoned, you can supply Crashlytics.instance.recordError to the onError parameter:

runZoned<Future<void>>(() async {
    // ...
  }, onError: Crashlytics.instance.recordError);

Result #

If an error is caught, you should see the following messages in your logs:

flutter: Flutter error caught by Crashlytics plugin:
// OR if you use recordError for runZoned:
flutter: Error caught by Crashlytics plugin <recordError>:
// Exception, context, information, and stack trace in debug mode
// OR if not in debug mode:
flutter: Error reported to Crashlytics.

Note: It may take awhile (up to 24 hours) before you will be able to see the logs appear in your Firebase console.

Example #

See the example application source for a complete sample app using firebase_crashlytics.

Issues and feedback #

Please file Flutterfire specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue tracker.

To contribute a change to this plugin, please review our contribution guide, and send a pull request.

0.1.3+3 #

  • Fix for missing UserAgent.h compilation failures.

0.1.3+2 #

  • Fix Cirrus build by removing WorkspaceSettings.xcsettings file in the iOS example app.

0.1.3+1 #

  • Make the pedantic dev_dependency explicit.

0.1.3 #

  • Add macOS support

0.1.2+5 #

  • Fix overrides a deprecated API.
  • Raise minimum required Flutter SDK version to 1.12.13+hotfix.4

0.1.2+4 #

  • Updated the example with the missing recordError() method.
  • Added a recordError() integration test.

0.1.2+3 #

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Bump the minimum Flutter version to 1.10.0.

0.1.2+2 #

  • Removed the async from the runZoned() in the example, as there's no await to be executed.

0.1.2+1 #

  • Updated a confusing comment.

0.1.2 #

  • Updated to use the v2 plugin API.

0.1.1+2 #

  • When reporting to Crashlytics on iOS, and printing supplied logs, do not prepend each line with "FirebaseCrashlyticsPlugin.m line 44".
  • Prepend firebase_crashlytics: to the final answer from Crashlytics plugin in the log to realize where it's coming from.

0.1.1+1 #

  • Updated README instructions for contributing for consistency with other Flutterfire plugins.

0.1.1 #

  • Log FlutterErrorDetails using Flutter's standard FlutterError.dumpErrorToConsole.
  • In debug mode, always log errors.

0.1.0+5 #

  • Fix example app support-compat crash by setting compileSdkVersion to 28.

0.1.0+4 #

  • Fix linter finding in examples.

0.1.0+3 #

  • Update documentation to reflect new repository location.
  • Update unit tests to call TestWidgetsFlutterBinding.ensureInitialized.

0.1.0+2 #

  • [iOS] Fixes crash when trying to report a crash without any context

0.1.0+1 #

  • Added additional exception information from the Flutter framework to the reports.
  • Refactored debug printing of exceptions to be human-readable.
  • Passing null stack traces is now supported.
  • Added the "Error reported to Crashlytics." print statement that was previously missing.
  • Updated README.md to include both the breaking change from 0.1.0 and the newly added recordError function in the setup section.
  • Adjusted README.md formatting.
  • Fixed recordFlutterError method name in the 0.1.0 changelog entry.

0.1.0 #

  • Breaking Change Renamed onError to recordFlutterError.
  • Added recordError method for errors caught using runZoned's onError.

0.0.4+12 #

  • Update google-services Android gradle plugin to 4.3.0 in documentation and examples.

0.0.4+11 #

  • Fixed an issue where Crashlytics#getStackTraceElements didn't handle functions without classes.

0.0.4+10 #

  • Update README.

0.0.4+9 #

  • Fixed custom keys implementation.
  • Added tests for custom keys implementation.
  • Removed a print statement.

0.0.4+8 #

  • Automatically use version from pubspec.yaml when reporting usage to Firebase.

0.0.4+7 #

  • Fixed an issue where Crashlytics#setUserIdentifier incorrectly called setUserEmail on iOS.

0.0.4+6 #

  • On Android, use actual the Dart exception name instead of "Dart error."

0.0.4+5 #

  • Fix parsing stacktrace.

0.0.4+4 #

  • Add missing template type parameter to invokeMethod calls.
  • Bump minimum Flutter version to 1.5.0.

0.0.4+3 #

  • Migrate our handling of FlutterErrorDetails to work on both Flutter stable and master.

0.0.4+2 #

  • Keep debug log formatting.

0.0.4+1 #

  • Added an integration test.

0.0.4 #

  • Initialize Fabric automatically, preventing crashes that could occur when setting user data.

0.0.3 #

  • Rely on firebase_core to add the Android dependency on Firebase instead of hardcoding the version ourselves.

0.0.2+1 #

  • Update variable name enableInDevMode in README.

0.0.2 #

  • Updated the iOS podspec to a static framework to support compatibility with Swift plugins.
  • Updated the Android gradle dependencies to prevent build errors.

0.0.1 #

  • Initial release of Firebase Crashlytics plugin. This version reports uncaught errors as non-fatal exceptions in the Firebase console.

example/lib/main.dart

// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';

void main() {
  // Set `enableInDevMode` to true to see reports while in debug mode
  // This is only to be used for confirming that reports are being
  // submitted as expected. It is not intended to be used for everyday
  // development.
  Crashlytics.instance.enableInDevMode = true;

  // Pass all uncaught errors to Crashlytics.
  FlutterError.onError = Crashlytics.instance.recordFlutterError;

  runZoned(() {
    runApp(MyApp());
  }, onError: Crashlytics.instance.recordError);
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Crashlytics example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                  child: const Text('Key'),
                  onPressed: () {
                    Crashlytics.instance.setString('foo', 'bar');
                  }),
              FlatButton(
                  child: const Text('Log'),
                  onPressed: () {
                    Crashlytics.instance.log('baz');
                  }),
              FlatButton(
                  child: const Text('Crash'),
                  onPressed: () {
                    // Use Crashlytics to throw an error. Use this for
                    // confirmation that errors are being correctly reported.
                    Crashlytics.instance.crash();
                  }),
              FlatButton(
                  child: const Text('Throw Error'),
                  onPressed: () {
                    // Example of thrown error, it will be caught and sent to
                    // Crashlytics.
                    throw StateError('Uncaught error thrown by app.');
                  }),
              FlatButton(
                  child: const Text('Async out of bounds'),
                  onPressed: () {
                    // Example of an exception that does not get caught
                    // by `FlutterError.onError` but is caught by the `onError` handler of
                    // `runZoned`.
                    Future<void>.delayed(const Duration(seconds: 2), () {
                      final List<int> list = <int>[];
                      print(list[100]);
                    });
                  }),
              FlatButton(
                  child: const Text('Record Error'),
                  onPressed: () {
                    try {
                      throw 'error_example';
                    } catch (e, s) {
                      // "context" will append the word "thrown" in the
                      // Crashlytics console.
                      Crashlytics.instance
                          .recordError(e, s, context: 'as an example');
                    }
                  }),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  firebase_crashlytics: ^0.1.3+3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_crashlytics/firebase_crashlytics.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
98
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:firebase_crashlytics/firebase_crashlytics.dart]

Package does not support Flutter platform web

Because of import path [package:firebase_crashlytics/firebase_crashlytics.dart]

Package does not support Flutter platform windows

Because of import path [package:firebase_crashlytics/firebase_crashlytics.dart]

Package not compatible with SDK dart

because of import path [firebase_crashlytics]

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
stack_trace ^1.9.3 1.9.5
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.0
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
e2e ^0.2.1
flutter_driver
flutter_test
pedantic ^1.8.0
test ^1.5.1