react-native-exceptions-manager

0.2.0 • Public • Published

react-native-exceptions-manager

GitHub license NPM version Dependency Status Downloads

React-Native Crash Reporter In Release Version(Do not trigger native crash).

Linking

Android

  • Add following lines into android/settings.gradle
include ':react-native-exceptions-manager'
project(':react-native-exceptions-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exceptions-manager/android/app')
  • Add following lines into your android/app/build.gradle in section dependencies
compile project(':react-native-exceptions-manager')
  • Add following lines into MainApplication.java
import com.richardcao.exceptionsmanager.react.ExceptionsManager;
...

@Override
protected List<ReactPackage> getPackages() {
    List<ReactPackage> packages = Arrays.asList(
            new MainReactPackage(),
            ...);
    ArrayList<ReactPackage> packageList = new ArrayList<>(packages);
    if (!BuildConfig.DEBUG) {
        packageList.add(new ExceptionsManager());
    }
    return packageList;
}
  • Create a class named ReactNativeJSCrashReceiver in it. This is needed to get js crash message from react-native-exceptions-manager.
public class ReactNativeJSCrashReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("com.richardcao.android.REACT_NATIVE_CRASH_REPORT_ACTION")) {
            Throwable js = (Throwable) intent.getSerializableExtra("JavascriptException");
            ...(handler or report js crash operate)
            Throwable e = (Throwable) intent.getSerializableExtra("Exception");
            ...(handler or report native crash operate)
        }
    }
}
  • Add ReactNativeJSCrashReceiver declare in your AndroidManifest.xml
<application
    android:name=".MainApplication"
    android:allowBackup="true"
    ...>
    ...
    <receiver android:name=".ReactNativeJSCrashReceiver">
        <intent-filter>
            <action android:name="com.richardcao.android.REACT_NATIVE_CRASH_REPORT_ACTION" />
        </intent-filter>
    </receiver>
</application>

iOS

//TODO

Who Use It

MIT Licensed

Package Sidebar

Install

npm i react-native-exceptions-manager

Weekly Downloads

88

Version

0.2.0

License

MIT

Last publish

Collaborators

  • richardcao