GithubHelp home page GithubHelp logo

mqch295 / firebase_crashlytics Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 151 KB

License: BSD 3-Clause "New" or "Revised" License

Java 23.06% Objective-C 13.97% Dart 54.02% Swift 2.65% Ruby 6.30%

firebase_crashlytics's Introduction

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.

The following instructions are from the official installation page.

Android integration

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

  1. Check that you have Google's Maven repository in your project-level build.gradle file ([project]/android/build.gradle).
buildscript {
  repositories {
    // Add this
    google()

    // ... you may have other repositories
  }
}
allprojects {
  repositories {
    // and this
    google()

    // ...
  }
}
  1. Add the following classpaths to your project-level build.gradle file ([project]/android/build.gradle).
buildscript {
  dependencies {
    // Check that you have the Google Services Gradle plugin v4.3.2 or later (if not, add it).
    classpath 'com.google.gms:google-services:4.3.3'
    
    // Add the Crashlytics Gradle plugin.
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0'

    // ... you may have other classpaths
  }
}
  1. Apply the following plugins in your app-level build.gradle file ([project]/android/app/build.gradle).
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
  1. Add the SDK dependencies in your app-level build.gradle file ([project]/android/app/build.gradle).
dependencies {
  // Optional but recommended: Add the Firebase SDK for Google Analytics.
  implementation 'com.google.firebase:firebase-analytics:17.4.0'

  // Add the Firebase SDK for Crashlytics.
  implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
}

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}/FirebaseCrashlytics/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 runZonedGuarded, you can supply Crashlytics.instance.recordError to the onError positioned parameter:

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

Finally, to catch errors that happen outside Flutter context, install an error listener on the current Isolate:

Isolate.current.addErrorListener(RawReceivePort((pair) async {
  final List<dynamic> errorAndStacktrace = pair;
  await Crashlytics.instance.recordError(
    errorAndStacktrace.first,
    errorAndStacktrace.last,
  );
}).sendPort);

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 runZonedGuarded:
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.

firebase_crashlytics's People

Contributors

mqch295 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.