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

后端 未结 3 522
情深已故
情深已故 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!

    0 讨论(0)
  • 2021-02-04 08:09

    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>"
      />
    
    0 讨论(0)
  • 2021-02-04 08:21

    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

    0 讨论(0)
提交回复
热议问题