1

I am 100% new to Java and I'm trying to add Crashlytics to my React Native project. The only code snippet I could find on the internet is retrolambda syntax.

I realize I could add that particular "library" or whatever, so it works, but considering it's the only place used in my project I'd rather just convert it to the 'older format' rather than adding a library just to do one function.

public final class AppReactPackage implements ReactPackage {

  @Override
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    addExceptionHandler(reactContext);
  }

  private void addExceptionHandler(ReactApplicationContext reactContext) {
    // Fyi, this is using Retrolambda for Java 8 syntax
    reactContext.setNativeModuleCallExceptionHandler(e -> {
      if (e instanceof JavascriptException) {
        Crashlytics.log(e.getMessage());
      } else {
        Crashlytics.logException(e);
      }
    });
  }
}
Tallboy
  • 12,847
  • 13
  • 82
  • 173

1 Answers1

3

Searching your syntax I found these two links:

  1. React
  2. NativeModuleCallExceptionHandler

By using those, it should look something like this: (untested)

private void addExceptionHandler(ReactApplicationContext reactContext) {
    reactContext.setNativeModuleCallExceptionHandler(new NativeModuleCallExceptionHandler() {
        @Override
        public void onHandleException(Exception e) {
            if (e instanceof JavascriptException) {
                Crashlytics.log(e.getMessage());
            } else {
                Crashlytics.logException(e);
            }
        }
    });
}
Tallboy
  • 12,847
  • 13
  • 82
  • 173
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115