在Android项目的build.gradle文件中添加以下依赖项:
dependencies {
// ...
implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
// Add the following line:
implementation 'com.google.firebase:firebase-analytics:18.0.0'
}
然后,在终端中运行以下命令:
npm install --save @react-native-firebase/crashlytics
最后,在React Native项目的MainActivity.java文件中导入FirebaseCrashlytics包,并在onCreate方法中初始化FirebaseCrashlytics:
import com.google.firebase.crashlytics.FirebaseCrashlytics;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseApp.initializeApp(this); // Add this line
// ...
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
}
// ...
}