Fabric is a modular mobile platform that provides useful kits you can mix to build your application. Crashlytics is a crash and issue reporting tool provided by Fabric that allows you to track and monitor your applications in detail.
Step 1: Change your build.gradle
:
Add the plugin repo and the gradle plugin:
buildscript {
repositories {
maven { url '<https://maven.fabric.io/public>' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
Apply the plugin:
apply plugin: 'com.android.application'
//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'
Add the Fabric repo:
repositories {
maven { url '<https://maven.fabric.io/public>' }
}
Add the Crashlyrics Kit:
dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true;
}
}
Step 2: Add Your API Key and the INTERNET permission in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="<http://schemas.android.com/apk/res/android>">
<application
... >
<meta-data
android:name="io.fabric.ApiKey"
android:value="25eeca3bb31cd41577e097cabd1ab9eee9da151d"
/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Step 3: Init the Kit at runtime in you code, for example:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Init the KIT
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main);
}
}
Step 4: Build project. To build and run: