8

I'm trying to get the Firebase - Firestore database emulator to work on my physical IOS device via the Expo application while I develop.

I can get Localhost to work in a browser and 10.0.2.2:(8080) to work via Android emulator. However, I cannot get my PHYSICAL IOS device, to work. I get firebase couldn't connect within 10 seconds error.

Tried localhost, tried the ip provided in the expo app 192.168.x.x tried the ip address given in my current wifi location, nothing.

I'm using this piece of code to connect Android Emulator / Web browswer

firebase.firestore().settings({ 
    experimentalForceLongPolling: true,
    host: '10.0.2.2:8084',
    ssl: false})
Anakhand
  • 2,838
  • 1
  • 22
  • 50
eyerishluv
  • 91
  • 1
  • 4

2 Answers2

24

In your firebase.json set a host parameter of "0.0.0.0" for every emulator you're using.

Code I use to connect to the emulator w/ a real iOS device is below

firebase.json

{
  "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"
    },
    "database": {
      "port": 9000,
      "host": "0.0.0.0"
    },
    "ui": {
      "enabled": true
    }
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "database": {
    "rules": "database.rules.json"
  }
}

Then on the client add

realtimeDatabase.useEmulator(yourLocalIp, 9000);
firestore.useEmulator(yourLocalIp, 8080);
firebase.functions().useEmulator(yourLocalIp, 5001);     
auth.useEmulator('http://yourLocalIp:9099')

Make sure that your network profile on your host is set as 'Private' or 'Trusted', and that you don't have any antivirus/firewall blocking external connections.

Gwater17
  • 2,018
  • 2
  • 19
  • 38
  • I don't have useEmulator method as an option. I might need to update my Firebase, currently I use settings method to get it to work in the Android Emulator. Do you know if there is a way to get it done with the settings method? I believe your answer is correct though for those who already have the proper version of Firebase which includes useEmulator. Thanks. – eyerishluv Feb 24 '21 at 14:41
  • FYI Firebase version 9.1.0 – eyerishluv Feb 24 '21 at 14:51
  • 1
    what is "yourLocalIp" here? 0.0.0.0? – bze12 Nov 21 '21 at 21:45
  • "yourLocalIp" is your computer's local IP address. 192.168.x.y where x and y are specific to your computer. – troyshu Dec 29 '21 at 15:57
  • 1
    The setup in this answer doesn't work for me. My app (using Android simulator) connects to _something_ but is not reading or writing anything. But this was also the behavior when I didn't set the "host" values in `firebase.json` and just connected to `localhost` in `FirebaseFirestore.instance.useFirestoreEmulator`... – troyshu Dec 29 '21 at 15:58
  • *If you are using Android 8+ :* Make sure to add ` – Paul Dec 29 '21 at 17:04
0

Final answer. Update your packages. (I'm pissed at myself)

I spent countless hours trying to figure out a problem that didn't have a solution yet cause it came out in future versions.

So I had Firebase javascript sdk 7.9 after updating to sdk 8.29 it worked perfect on a physical IOS device. I didn't use useEmulator, I use this piece of code.

if(firebase.apps.length === 0){
       
    firebase.initializeApp(config)      
        
    firebase.firestore().settings({ 
         experimentalForceLongPolling: true,
         host:'192.168.X.XX:8089'         
         ,ssl:false
         })        

    } else {      
        firebase.app()
    }

export default firebase

settings method worked great for me, not sure if i'll find other issues not using the useEmulator or if that is for different types of platforms. I'm using expo/React Native.

Thanks for responses.

eyerishluv
  • 91
  • 1
  • 4
  • This is now deprecated and you have to use `useEmulator`. The previous answer worked for me. https://stackoverflow.com/a/66321658/12331115 – Adham Sep 14 '22 at 12:35