react-native - Expo 不适用于 firebase 模拟器

标签 react-native google-cloud-firestore expo firebase-tools

我正在尝试通过我的 Expo 应用程序在物理设备和模拟设备上访问 firestore 模拟器(本地托管),但这两者都不起作用。当我调用模拟的 Firestore 数据库(例如设置文档)时,它不会显示在 UI 上。但是,如果我为真正的 firestore 运行完全相同的代码,它会正常工作。

我的 firebase.json 配置是:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "emulators": {
    "firestore": {
      "port": 8080
    },
  }
}

对于 Android 模拟器上的 Expo 应用程序,我将配置设置为:

firebase.firestore().settings({
  host: "10.0.2.2:8080", 
  ssl: false,
})

对于我的 Android 物理设备上的 Expo 应用程序:

firebase.firestore().settings({
  host: "localhost:8080",  
//I've also tried "192.168.68.109:8080" my computer's IP
  ssl: false,
})

最佳答案

事实证明,您需要将 firebase.json 上的主机指定为

"emulators": {
    "firestore": {
      "port": 8080
      "host": "0.0.0.0"
    },

对于物理设备上的 Expo 应用程序的配置,不要使用“localhost:8080”,而是使用您的计算机(或网络中的任何主机)的 IP 地址,后跟“:8080”。

如果这一切仍然不起作用,请在项目目录中尝试命令“firebase use ”,它应该可以工作。

关于react-native - Expo 不适用于 firebase 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65512580/

相关文章:

javascript - Firestore : Unable to fetch nested documents. 为什么?

ios - facebook 登录错误,react-native ios expo

json - 警告未定义的软件包已被忽略,因为它包含无效的配置。原因 : Cannot find module 'undefined/package.json'

javascript - React Native FBSDK 处理身份验证拒绝

swift - FireStore Swift 4 : How to get total count of all the documents inside a collection, 并获取每个文件的详细信息?

google-cloud-firestore - 为什么对于确实存在的项目,Firebase API 对projects.databases.get 的调用会返回错误 404 - 项目不存在?

javascript - Asset.fromModule 不是函数。 (在 'Asset.fromModule(image)' 中, 'Asset.fromModule' 未定义)

javascript - 为什么 react-native-gifted-chat 不能从 firebase 时间戳正确显示时间?

ios - xcode 'boost/config/user.hpp' 找不到文件

android - 在搭载 Android 7 的三星 S7 上使用 React Native 时 libjsc.so 中的 native 崩溃