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

后端 未结 3 514
情深已故
情深已故 2021-02-04 07:23

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

3条回答
  •  清酒与你
    2021-02-04 08:02

    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!

提交回复
热议问题