Firebase Cloud Function: & Flutter: Cannot use https callable function on emulators [firebase_functions/unavailable] UNAVAILABLE

879

The problem was that my physical device cannot connect to localhost of my laptop. Using Android Emulator solved my problem

Share:
879
Đặng Minh Hiếu
Author by

Đặng Minh Hiếu

Updated on November 27, 2022

Comments

  • Đặng Minh Hiếu
    Đặng Minh Hiếu over 1 year

    I'm trying to call a HTTPS callable function using emulators, from my flutter application, but it seems not to work. After I call the function, it always takes around 5 seconds and responds with an error. It works completely normal if I deploy the function on the server instead.

    Here is my function

    exports.try = functions.https.onCall((data, context) => {
      return 1;
    });
    

    It is located at us-central1

    How I started the emulators

    firebase emulators:start --only functions
    

    How I called it from the code

    FirebaseFunctions functions = FirebaseFunctions.instance;
    functions.useFunctionsEmulator(origin: "http://10.0.2.2:5001");
    HttpsCallable callable = functions.httpsCallable('games-oneToHundred-try');
    try {
      var result  = await callable();
      print(result.data);
    } catch (e) {
      print(e);
    }
    

    The error is thrown is:

    [firebase_functions/unavailable] UNAVAILABLE
    

    I modified the android manifest as suggested in Error connecting to local Firebase functions emulator from Flutter app like the following:

    android:usesCleartextTraffic="true"
    
  • Đặng Minh Hiếu
    Đặng Minh Hiếu about 3 years
    I've already tried localhost and also did what that post suggested, as you can see from my reference link. Both of those solutions doesn't work for me
  • maganap
    maganap over 2 years
    Consider listening on 0.0.0.0 from your emulator is you still want to use your real device: stackoverflow.com/q/67973536/2619537