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:
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' } }
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' }
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:
- From Xcode select
Runner
from the project navigation. - Select the
Build Phases
tab. - Click
+ Add a new build phase
, and selectNew Run Script Phase
. - Add
${PODS_ROOT}/Fabric/run
to theType a script...
text box. - If you are using Xcode 10, add the location of
Info.plist
, built by your app, to theBuild 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);