firebase firestore 在 .get() 方法之后使应用程序崩溃

firebase firestore crashes app after .get() method

我正在用 react-native 0.57.0 实现 react-native-firebase 5.2.0。

我已经完成文档中要求的所有配置,但是,当我要使用 firebase firestore 执行查询时,应用程序崩溃了!

在调试时我可以看到查询确实执行成功,但不是没有关闭应用程序。

这些是我正在执行的代码:

componentDidMount() {
firebase.firestore().collection('users').get().then((snap) => {
  console.log(snap);
});}

明确一点,执行时没有错误,只是应用程序关闭。

只有当我对 firestore 使用某些方法时才会发生这种情况,例如 .get()、.add()、.update() 等...

有人可以帮我吗?

您最好通过 adb logcat 直接查看您的 USB 设备是否有错误,因为它们比应用程序日志(红屏)更详细。

因为 logcat 即使应用程序完全崩溃,也总是会记录错误,并且无法显示红屏。

Android-Studio 可以用作 logcat 的漂亮 GUI,甚至像其他一些应用程序一样 (https://github.com/search?q=logcat)

如何在 Android-Studio

中启动 Logcat

如果您使用 android-studio,请确保将项目文件夹中的 /android-目录用作项目根目录(不要使用你的 react-native-project-root !)。然后按 SHIFT 几次 并输入 Logcat

打开 Logcat

在 Android

将此添加到我的 android/app/build.gradle 为我解决了这个问题:

dependencies {
  // Your over dependencies
  // ...
  implementation "io.grpc:grpc-okhttp:1.32.2"
  // ...
}

我在使用 Android Studio 启动应用程序时看到了错误并得到了这个:

E/androidruntime: fatal exception: grpc-okhttp-0

Here 这是我从哪里得到的。