Reputation: 633
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!!
Upvotes: 9
Views: 3106
Reputation: 616
Using flutter on a macbook, 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);
Upvotes: 2
Reputation: 633
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.
Upvotes: 15