-1

I try to use Firebase Cloud Functions from my Flutter application by using the Firebase Emulator. In production, the call is working fine, but not in the Emulator, I always get the following error.

Error after calling the function

[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: PlatformException(-5, The operation couldn’t be completed. (com.google.GTMSessionFetcher error -5.), null)

Flutter code

CloudFunctions(region: "europe-west3")
              .useFunctionsEmulator(origin: "127.0.0.1:8080")
              .getHttpsCallable(
                functionName: "addUser",
              )
              .call(
            {"name": "oui", "email": "oui@oui.fr"},
          ).then(
            (value) {
              print('OK');
              print(value);
            },
          );

firebase.json

{
  "emulators": {
    "functions": {
      "port": 5001
    },
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    },
    "ui": {
      "enabled": true
    }
  }
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Lab
  • 1,237
  • 2
  • 13
  • 30

1 Answers1

1

In the firebase.json port for function emulator is setup to 5001, while in presented code useFunctionsEmulator method is calling on 8080. This port is set for firestore emulator.

According to documentation parameter should be:

Changes this instance to point to a Cloud Functions emulator running locally.

@param origin The origin of the local emulator, such as "//10.0.2.2:5005".

Although it's not straight I suppose the doc means function emulator.

vitooh
  • 4,132
  • 1
  • 5
  • 16
  • Thank you for your response. I changed the port number, but still the same error (com.google.GTMSessionFetcher error -5.). I tried to directly put "http://localhost:5001/.../europe-west3/fetchUserData" in my navigator and I get the call. So I'm sure the problem come from the cloud function call in my Flutter app. I can show more details if you need. – Lab Sep 21 '20 at 16:40
  • How do you testing it? Is this some kind of iOS simulator...? – vitooh Sep 29 '20 at 10:18
  • Yes IOS simulator. – Lab Sep 29 '20 at 10:27
  • This might be a meter of virtualization. IOS simulator is virtual machine, so practically this is trying to reach simulator from different machine, not locally. This might be the reason as this is Firebase Local Emulator Suite, it's not designed to work on remote machine. – vitooh Oct 01 '20 at 06:19
  • Find it! Just have to had http in front of the url: cloudFunctions.useFunctionsEmulator(origin: "http://127.0.0.1:5001") – Lab Oct 11 '20 at 18:48