14

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?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
BigPun86
  • 2,480
  • 2
  • 25
  • 49

3 Answers3

12

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!

BigPun86
  • 2,480
  • 2
  • 25
  • 49
  • I think using [NativeModuleCallExceptionHandler](https://github.com/facebook/react-native/pull/4782#issuecomment-165056536) is the way to log the JS exception messages, too. – Ben Manes Dec 18 '15 at 02:01
  • I´ll give it a try in the next days...Thanks – BigPun86 Dec 18 '15 at 15:37
  • I get the following error :/ ERROR - Crashlytics Developer Tools error. java.lang.IllegalArgumentException: Crashlytics found an invalid API key: null. Check the Crashlytics plugin to make sure that the application has been added successfully! Contact support@fabric.io for assistance. – jay shah Dec 19 '15 at 20:39
  • You need to get the API key from Fabric.io – BigPun86 Dec 19 '15 at 20:41
  • Go to https://fabric.io/settings/organizations/ and get your organisations api key – BigPun86 Jan 14 '16 at 16:15
  • there's no onCreate method in my MainActivity (react native 0.21).. :/ – Dave Mar 09 '16 at 00:00
  • 2
    You should be able to add one. Just make sure to import android.os.Bundle;. And then you can override the method – chapinkapa Mar 22 '16 at 23:52
  • I did not have the onCreate method. Added it and things work great. Thanks! – Code Monkey Apr 04 '16 at 09:21
  • @BigPun86 Did you ever manage to implement [NativeModuleCallExceptionHandler](https://github.com/facebook/react-native/pull/4782#issuecomment-165056536)? Trying to do so myself... https://stackoverflow.com/questions/38225845/integrating-crashlytics-into-react-native-android – Barnabus Jul 07 '16 at 09:53
  • @Barnabus Unfortunatley i dind´t find the time yet :/ – BigPun86 Nov 23 '16 at 15:46
4

For the newer versions of React Native you have to import Bundle and place your own onCreate Method like this:

// Added Bundle to use onCreate which is needed for our Fabrics workaround
import android.os.Bundle;

..........

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

}

Not sure if this is good or not since they have removed the onCreate but it works for me

BigPun86
  • 2,480
  • 2
  • 25
  • 49
0

Try this : https://fabric.io/kits/android/crashlytics/install

Summarizes all the files you need to edit in your Android installation well. For the AndroidManifest.xml file, replace the android:value key (e.g. below) with your actual API key. Remember to get your API key from your organization settings... 1. login to https://fabric.io/settings/organizations and 2. click on build secret.

      <meta-data
      android:name="io.fabric.ApiKey"
      android:value="<api key here>"
  />