android - Firebase Firestore:无法访问 Firestore 后端(仅限 Android)
问题描述
我正在react-native
使用Create React Native App
. 对于它使用的后端Firebase Firestore
。该应用程序在 iOS 上运行良好,但在尝试从后端获取数据时在 Android 上失败并出现以下错误(无论是在模拟器上还是在设备上):
22:02:37: [2018-05-22T05:02:33.751Z] @firebase/firestore:, Firestore (4.10.1): Could not reach Firestore backend.
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:71:16 in error
- node_modules\@firebase\logger\dist\cjs\src\logger.js:97:25 in defaultLogHandler
- ... 18 more stack frames from framework internals
知道可能是什么问题以及如何调试吗?
该错误似乎是通用的,因为还有其他带有相同错误消息的问题。但在这种情况下,它仅适用于 Android。
完整日志和堆栈跟踪:
21:50:51: Warning: Expo version in package.json does not match sdkVersion in manifest.
21:50:51:
21:50:51: If there is an issue running your project, please run `npm install` in C:\Users\grigor\Documents\Bitbucket\AwesomeProject and restart.
21:51:08: Finished building JavaScript bundle in 26098ms
21:51:14: Running app on XT1053 in development mode
21:51:34: [2018-05-25T04:51:26.597Z] @firebase/firestore:, Firestore (4.10.1): Could not reach Firestore backend.
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:71:16 in error
- node_modules\@firebase\logger\dist\cjs\src\logger.js:97:25 in defaultLogHandler
- ... 18 more stack frames from framework internals
21:51:37: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 3299464ms)
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:82:15 in warn
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:254:8 in setTimeout
- node_modules\@firebase\auth\dist\auth.js:37:577 in Hc
* null:null in <unknown>
- node_modules\@firebase\auth\dist\auth.js:15:932 in y
- node_modules\@firebase\auth\dist\auth.js:37:606 in Ic
- node_modules\@firebase\auth\dist\auth.js:210:0 in kk
- node_modules\@firebase\auth\dist\auth.js:209:665 in start
- node_modules\@firebase\auth\dist\auth.js:215:38 in Dk
- node_modules\@firebase\auth\dist\auth.js:253:425 in ql
- node_modules\@firebase\auth\dist\auth.js:255:146 in <unknown>
- node_modules\@firebase\auth\dist\auth.js:19:220 in <unknown>
* null:null in Gb
* null:null in Cb
- node_modules\@firebase\auth\dist\auth.js:22:103 in Sb
- node_modules\@firebase\auth\dist\auth.js:15:643 in jb
- ... 10 more stack frames from framework internals
解决方案
我没有针对该问题的确切解决方案,但我意识到我与之交互的方式firebase
使我的应用程序更容易受到影响。也许你能在你的项目中发现我自己的一些设计缺陷?
我发现我是initializeApp
在 a 之外调用的try/catch
,这意味着只要遇到错误,整个 JavaScript 模块就会失败。因此,第一个解决方法是安全地正确处理初始化。
其次,这个错误在我构建对firestore()
. 例如,我的第一次调用firebase.firestore()
嵌入在返回 a 的方法中Promise
,即:
() => firebase.firestore().collection('someCollection').get().then(...).catch(e => ...);
firestore
现在,使用这种方法,如果在返回a 之前与 failed的交互Promise
,我们实际上不会catch
出错!这是因为它在链中出现得太早Promise
而无法创建。这再次意味着,应用程序似乎会在比应用程序内部捕获的东西更深的层面上失败。但这是错误的!
正确的实现是将交互包装firebase.firestore()
在Promise
第一个:
return new Promise(resolve => firebase.firestore().collection(...)).then(q => ...).catch(e =>...);
希望这在某种程度上有所帮助。我知道这是一个棘手的问题!
推荐阅读
- gulp - Gulp - 返回 browserSync 的错误
- php - 在 Laravel API 请求中更新多对多关系后返回模型时出错
- php - Symfony 4 自定义注解问题@ORM\Entity 不存在
- php - MySQL DAYNAME 明智的数据检索不同时区
- docker - Shell Runner 的所有权问题
- java - 用于在java中提取单词和换行符之间的字符串的正则表达式
- xcode - 读取错误.. node_modules/react-native/ReactCommon/jsinspector/InspectorInterfaces.cpp'
- javascript - 无法读取未定义的属性“文件”
- java - 调试由 docker 容器中的脚本调用的 java 应用程序
- python - 如何使用 Google 的视觉 API 从单个调用中注释多个图像?Python