react-native-crash-reporter v0.5.0
react-native-crash-reporter
react-native-crash-reporter
is a small library that hooks into the JavaScript error system and reports the unrolled stack trace to the native side. On the native side a callback will be called where the error information can be forwarded to a crash reporting system of choice. To be able to unroll the error it uses the sourcemap, which is automatically created while the React Native bundle is generated
Getting started
$ npm install react-native-crash-reporter --save
Mostly automatic installation
$ react-native link react-native-crash-reporter
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-crash-reporter
and addMSRCrashReporter.xcodeproj
- In XCode, in the project navigator, select your project. Add
libMSRCrashReporter.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import net.mischneider.MSRCrashReporterPackage;
to the imports at the top of the file - Add
new MSRCrashReporterPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-crash-reporter' project(':react-native-crash-reporter').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-crash-reporter/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-crash-reporter')
Usage
First is to define how the native part should handle crash reports. On Android register a listener on the MSRCrashReporterModule
:
MSRCrashReporterModule.getInstance().setOnRecordCustomExceptionCallback(new MSRCrashReporterModule.OnCrashReporterRecordCustomExceptionCallback() {
@Override
public void recordCustomException(Exception e) {
// TODO: Handle the exception
}
});
On iOS register a listener block on the MSRCrashReporter
singleton:
[MSRCrashReporter sharedReporter].recordCustomExceptionHandler = ^(NSString * _Nonnull name, NSString * _Nonnull reason, NSArray<MSRCrashReporterStackFrame *> * _Nonnull frameArray) {
// TODO: Handle crash
};
Initialize the crash reporter usually in your index.js
of your app:
import { init as initCrashReporting } from 'react-native-crash-reporter';
initCrashReporting({ captureOnDebugMode: false });