I've successfully set up Crashlytics integration for iOS for our React Native project, and have managed to get the android version registered as well. The only problem is that it only reports Java/system related crashes - if there is a javascript exception thrown it doesn't register with the reporting. I would like to get it working, as the iOS version has the functionality already.
I've set up the reporting as outlined in the Fabric docs and this question - see the second answer down, I've added the onCreate
in MainActivity.
Following up I have attempted to create my own NativeModuleCallExceptionHandler as per this issue comment. Code for this is below:
package com.mypackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.modules.core.JavascriptException;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import java.util.Map;
import com.crashlytics.android.Crashlytics;
class CrashlyticsErrorModule extends ReactContextBaseJavaModule {
public CrashlyticsErrorModule (ReactApplicationContext reactContext) {
super(reactContext);
addExceptionHandler(reactContext);
}
@Override
public String getName() {
return "CrashlyticsErrorModule";
}
private void addExceptionHandler(ReactApplicationContext reactContext) {
reactContext.setNativeModuleCallExceptionHandler(new NativeModuleCallExceptionHandler() {
@Override
public void handleException(Exception e) {
if (e instanceof JavascriptException) {
Crashlytics.log(e.getMessage());
} else {
Crashlytics.logException(e);
}
}
});
}
The code compiles with no errors, however Javascript exceptions are still not being reported.
Even when deliberately throwing runtime exceptions in onCreate()
or at the end of the addExceptionHandler()
method, handleException()
does not get called. Crashlytics does get notified however, so the exceptions are getting caught somewhere!!
Links to the source code are in the issue comment above.