How do I use Crashlytics for my React Native Android App?

BigPun86 picture BigPun86 · Nov 3, 2015 · Viewed 7.5k times · Source

I am trying to figure out how to use Crashlytics from Fabric for my React Native Android APP. I followed the steps on the Fabric homepage and added some lines in my build.gradle files. But the builds always crash.

Is there a difference using Crashlytics for React Native Android and Crashlytics for Native Android development using Android Studio and Java?

Answer

BigPun86 picture BigPun86 · Dec 9, 2015

I got it working in some way, but it may not be the perfect solution...

1: Add fabric/crashlytics into your app/build.gradle - File (I didn´t have the buildscript in my app/build.gradle so i just included it. But i am not sure if this is good....)

buildscript {
  repositories {
     jcenter()
     maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    // The Fabric Gradle plugin uses an open ended version to react
    // quickly to Android tooling updates
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

// Add this directly under: apply plugin: "com.android.application"
apply plugin: 'io.fabric'

// and this directly under: apply from: "react.gradle"
repositories {
  jcenter()
  maven { url 'https://maven.fabric.io/public' }
}

// Last but not least add Crashlytics Kit into dependencies
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true
}

2: The most important, because it is nowhere mentioned (or i didn´t find it anywhere), import Crashlytics and Fabric into MainActivity:

import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

3: In your onCreate - method add:

// Fabrics
Fabric.with(this, new Crashlytics());

When you´ve done this, you will at least get Crashreports which are caused by native Code (Java Code). Crashes which are caused through JS - Syntax or similar wont be notified. There you will get the known RedBox :P

Good luck!