简体   繁体   中英

firebase emulator with real devices

I am building a react-native app. And I want to test my code on real devices. Has anybody tried the firebase emulator with real iphone/android devices? In my case,Firebase emulator worked fine with the Android emulator/Iphone simulator but not with real devices. I am getting the following error.

Error [Error: [auth/network-request-failed] A network error (such as timeout, interrupted connection or unreachable host) has occurred.]

Thanks in advance!!

Finally, I am able to run firebase emulator with real devices. Thats how firebase.json looks like. I added the "host":"192.168.1.114". 192.168.1.114 is the IP assigned to your computer by router.

{
  "emulators": {
    "auth": {
      "host":"192.168.1.114",
      "port": 9099
    },
    "functions": {
      "host":"192.168.1.114",
      "port": 5001
    },
    "firestore": {
      "host":"192.168.1.114",
      "port": 8080
    },
    "ui": {
      "enabled": true
    }
  }
}

After changing the firebase.json. I added the following lines for auth and firestore respectively.

auth().useEmulator("http://192.168.1.114:9099");
firestore().settings({ host: "192.168.1.114:8080", ssl: false });

After these changes, I was able to push data to the firebase emulator from real devices. Your computer and devices should be connected with the same network.

This is what worked for me:

...
  "emulators": {
    "auth": {
      "port": 9099,
      "host": "0.0.0.0"
    },
    "functions": {
      "port": 5001,
      "host": "0.0.0.0"
    },
    "firestore": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "storage": {
      "port": 9199,
      "host": "0.0.0.0"
    },
    "ui": {
      "enabled": true
    }
  }
...

then in my flutter app:

// the ip to my computer
const localHostString = '192.168.1.81';
await FirebaseAuth.instance.useAuthEmulator(localHostString, 9099);
FirebaseFirestore.instance.useFirestoreEmulator(localHostString, 8080);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM