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

六眼飞鱼酱① 提交于 2019-12-03 11:41:00

问题


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?


回答1:


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!




回答2:


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




回答3:


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>"
  />


来源:https://stackoverflow.com/questions/33501522/how-do-i-use-crashlytics-for-my-react-native-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!