Crashlytics Integration
This setup keeps react-native-global-exception-handler as the single registration point for crash handling while sending reports to Firebase Crashlytics.
Install the dependencies
- npm
- Yarn
- pnpm
- Bun
npm install react-native-global-exception-handler @react-native-firebase/app @react-native-firebase/crashlytics
cd ios && pod install
yarn add react-native-global-exception-handler @react-native-firebase/app @react-native-firebase/crashlytics
cd ios && pod install
pnpm add react-native-global-exception-handler @react-native-firebase/app @react-native-firebase/crashlytics
cd ios && pod install
bun add react-native-global-exception-handler @react-native-firebase/app @react-native-firebase/crashlytics
cd ios && pod install
Then complete the core package setup from Installation.
Record JavaScript exceptions
If you already have Crashlytics initialized, the smallest useful setup looks like this:
import crashlytics from '@react-native-firebase/crashlytics';
import { setJSExceptionHandler } from 'react-native-global-exception-handler';
setJSExceptionHandler((error, isFatal) => {
crashlytics().recordError(error);
crashlytics().setAttribute('layer', 'javascript');
crashlytics().setAttribute('is_fatal', String(isFatal));
}, true);
Record native crash messages
Then register the native handler:
import { Platform } from 'react-native';
import crashlytics from '@react-native-firebase/crashlytics';
import { setNativeExceptionHandler } from 'react-native-global-exception-handler';
setNativeExceptionHandler((errorString) => {
crashlytics().log(errorString);
crashlytics().setAttribute('layer', 'native');
crashlytics().setAttribute('platform', Platform.OS);
}, {
forceAppToQuit: Platform.OS === 'android',
callPreviouslyDefinedHandler: false,
});
Recommended production pattern
import { Platform } from 'react-native';
import crashlytics from '@react-native-firebase/crashlytics';
import {
setJSExceptionHandler,
setNativeExceptionHandler,
} from 'react-native-global-exception-handler';
setJSExceptionHandler((error, isFatal) => {
crashlytics().recordError(error);
crashlytics().setAttributes({
layer: 'javascript',
is_fatal: String(isFatal),
});
}, true);
setNativeExceptionHandler((errorString) => {
crashlytics().log(errorString);
crashlytics().setAttributes({
layer: 'native',
platform: Platform.OS,
});
}, {
forceAppToQuit: Platform.OS === 'android',
callPreviouslyDefinedHandler: false,
});
What to watch for
- Crashlytics setup must already be complete for your app before these handlers run.
- Native exception handlers should not do heavy synchronous work.
- Android restart logic and
forceAppToQuitbehavior still matter even if Crashlytics is attached. Read Native Crash Handling before changing the defaults.
Verify before shipping
- Test a JavaScript exception in development.
- Use Simulate Native Crash in React Native in a release build.
- Confirm the events are visible in Firebase.
- Re-check Troubleshooting if callbacks are skipped or native builds fail.