This is a Cordova plugin for Fabric.io's Crashlytics and Answers services.
It requires Cordova 3.x or newer (tested on 5.4.0) and has APIs for iOS and Android.
The iOS version uses Fabric SDK 1.6.5 and Crashlytics SDK 3.6.0 framework bundles which are located in lib/ios
.
The Android version uses Gradle to get the Fabric SDK (io.fabric.tools:gradle:1.+
) and the Crashlytics SDK (com.crashlytics.sdk.android:crashlytics:2.5.5
) from Maven repositories when the plugin is added.
- Make sure that you have Node and Cordova CLI or PhoneGap's CLI installed on your machine.
- Setup your Fabric.io account and get your API Key and Build Secret from your organization page.
- Add a plugin to your project using Cordova CLI, specifying the keys with the
--variable
argument:
# Install from npm registry:
cordova plugin add cordova-fabric-plugin --variable FABRIC_API_KEY=XXX --variable FABRIC_API_SECRET=xxx
# Or to install directly from github:
# (replace x.x.x with the tag of the version your want, or omit for HEAD)
cordova plugin add https://github.com/sarriaroman/FabricPlugin#x.x.x --variable FABRIC_API_KEY=XXX --variable FABRIC_API_SECRET=xxx
The plugin is available via global variable named fabric
. It exposes APIs for both Crashlytics and Answers.
A TypeScript definition file for the JavaScript interface is available in the typings
directory.
See typings/cordova-fabric-plugin.d.ts
for documentation of the JavaScript APIs including call signatures and parameter types.
Below are a few examples; see the API documentation for a complete list.
window.fabric.Crashlytics.addLog("about to send a crash for testing!");
window.fabric.Crashlytics.sendCrash();
//Android and iOS
window.fabric.Crashlytics.addLog("about to send a non fatal crash for testing!");
window.fabric.Crashlytics.sendNonFatalCrash("Error message");
//iOS only. Send message and error code
window.fabric.Crashlytics.addLog("about to send a non fatal crash for testing!");
window.fabric.Crashlytics.recordError("Error message", -1);
Issue Grouping
Crashes are grouped via stack trace analysis. Logged errors are grouped, instead, by the error domain and code. Remember that this means error issues can span many different call sites.
window.fabric.Crashlytics.setUserIdentifier("123");
window.fabric.Crashlytics.setUserName("Some Guy");
window.fabric.Crashlytics.setUserEmail("[email protected]");
window.fabric.Crashlytics.setStringValueForKey("bar", "foo");
window.fabric.Answers.sendSignUp("Facebook", true);
var attributes = {
foo: "data",
bar: true,
};
window.fabric.Answers.sendSignUp("Facebook", true, attributes);
window.fabric.Answers.sendAddToCart(29.95, "USD", "Foo Bar Shirt", "apparel", "123");
A normal installation for the Fabric SDKs involves downloading the Fabric tool and pointing it at your native code project. This tool takes care of adding references and modifying your build scripts and/or project files.
This plugin instead performs these steps via two build hooks located in the hooks
directory: after_plugin_install
and before_plugin_uninstall
.
This allows you to avoid using the Fabric tool as well as omit your platforms
directory from source control.
The Fabric SDK comes with a command line tool that takes care of uploading debug symbols after a build so that they can be used when viewing crash reports.
For iOS, our build hook adds a build script phase block to execute Fabric's uploader command line tool.
For Android, our build hook modifies the build.gradle
file to delegate to Fabric's uploader Gradle task.
If you wish to contribute please see CONTRIBUTING.md
.