2

I am trying to connect to my Firebase functions emulators from my test Android device.

When I run the emulators the output is:

┌─────────────────────────────────────────────────────────────┐ │ ✔ All emulators ready! It is now safe to connect your app. │ │ i View Emulator UI at http://localhost:4000 │ └─────────────────────────────────────────────────────────────┘ ┌───────────┬────────────────┬─────────────────────────────────┐ │ Emulator │ Host:Port │ View in Emulator UI │ ├───────────┼────────────────┼─────────────────────────────────┤ │ Functions │ localhost:5001 │ http://localhost:4000/functions │ └───────────┴────────────────┴─────────────────────────────────┘ Emulator Hub running at localhost:4400 Other reserved ports: 4500 Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files. 

From my Flutter app, I do the following to connect:

FirebaseFunctions.instance.useFunctionsEmulator(origin: 'http://192.168.1.158:5001'); 

I have added android:usesCleartextTraffic="true" to my AndroidManifest and a network_security_config.xml as stated here and here.

I am getting all the time the following error:

PlatformException(firebase_functions, com.google.firebase.functions.FirebaseFunctionsException: INTERNAL, {code: unavailable, message: com.google.firebase.functions.FirebaseFunctionsException: INTERNAL}

What am I doing wrong?

3
  • Does origin: 'http://localhost:5001' work? Commented Jun 30, 2021 at 12:28
  • No @Dharmaraj, it's a physical device. Commented Jul 1, 2021 at 8:44
  • Then can you try firebase serve --host 0.0.0.0 so the emulators are available over the network? Commented Jul 1, 2021 at 8:48

1 Answer 1

5

By default, all the emulators will listen to localhost only and not your local network.

I tried replicating your issue by running my hosting emulator on the whole network and functions emulator only on localhost as in the following screenshot.

enter image description here

const firebaseConfig = {...} firebase.initializeApp(firebaseConfig); firebase.functions().useEmulator("192.168.0.102", 5001); var addMessage = firebase.functions().httpsCallable('addMessage'); addMessage({ text: "messageText" }).then((result) => { // Read result of the Cloud Function. var sanitizedMessage = result.data.text; }); 

I copied the sample function from the documentation and tried calling the function and as expected:

enter image description here

If you serve the functions using firebase serve --only functions --host 0.0.0.0 it should make functions available for your network.

Alternatively, you can specify that in your firebase.json like this:

{ "functions": { "predeploy": "npm --prefix \"$RESOURCE_DIR\" run build" }, "emulators": { "functions": { "port": 5001, "host": "0.0.0.0" } } } 

Then you can simply start the emulators using firebase emulators:start.

Sign up to request clarification or add additional context in comments.

1 Comment

YES.. I LIKE THAT YOU MENTIONED: Then you can simply start the emulators using firebase emulators:start. I was just changing the host but not restarting the emulators!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.