如何在 React Native 中实现 firebase crashlytics?

问题描述 投票:0回答:1

我正在为客户开发一个反应本机库。它可以无缝集成到任何 React Native 应用程序中。客户端已设置 Firebase 分析和 crashlytics。我想检测客户端应用程序中由于我的库或其他原因导致的任何崩溃。

我尝试将 Firebase Analytics 集成到我的库中,但经过相当大的努力,它最终给出了这个错误:

Error: You attempted to call "firebase.app('NAME_OF_MY_LIBRARY').analytics but; analytics does not support multiple Firebase Apps.

我想知道我是否可以在我的库中实现 crashlytics。如果是的话,我该怎么做?

firebase react-native crashlytics crashlytics-beta
1个回答
0
投票
Go to the Firebase Console (https://console.firebase.google.com/) and create a new project.
Follow the instructions to add Firebase to your Android and iOS apps. You'll need to provide your app's package name (Android) and bundle ID (iOS).
Download the google-services.json file for Android and GoogleService-Info.plist file for iOS, and place them in the appropriate directories in your React Native project.

npm install @react-native-firebase/app @react-native-firebase/crashlytics
cd ios && pod install && cd ..


Import Firebase in your index.js or App.js file:

import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import firebase from '@react-native-firebase/app';

if (!firebase.apps.length) {
  firebase.initializeApp();
}

AppRegistry.registerComponent(appName, () => App);

Import Crashlytics in the file where you want to use it:

import crashlytics from '@react-native-firebase/crashlytics';
crashlytics().log('This is a log`enter code here` message');
crashlytics().recordError(new Error('This is a non-fatal error'));
crashlytics().crash();
© www.soinside.com 2019 - 2024. All rights reserved.