Quickstart-android: Testing with a local instance of the Cloud Functions Emulator

Created on 14 Jul 2018  路  6Comments  路  Source: firebase/quickstart-android

The version 16.1.0 of the Cloud Functions Client SDK now allows us to test against a local instance of the Cloud Functions Emulator by using useFunctionsEmulator().

It would be nice to have a snippet showing this method's usage and maybe also include a link pointing to the Functions Emulator Docs.

functions feature request

Most helpful comment

For new visitors I put this into work:

        FirebaseFunctions.getInstance().useFunctionsEmulator("http://192.168.1.30:5000")
        FirebaseFunctions.getInstance()
                .getHttpsCallable("helloWorld")
                .call()
                .addOnCompleteListener { result -> }

And remember to make the firebase server accessible:
firebase serve --only functions
to
firebase serve --only functions --host 0.0.0.0

All 6 comments

@rosariopfernandes thanks for the suggestion! This is definitely something we should do.

For new visitors I put this into work:

        FirebaseFunctions.getInstance().useFunctionsEmulator("http://192.168.1.30:5000")
        FirebaseFunctions.getInstance()
                .getHttpsCallable("helloWorld")
                .call()
                .addOnCompleteListener { result -> }

And remember to make the firebase server accessible:
firebase serve --only functions
to
firebase serve --only functions --host 0.0.0.0

Any updates on this?

How to get logs? 馃摝

@jQrgen we have some docs on this here:
https://firebase.google.com/docs/emulator-suite/connect_and_prototype?database=Firestore#instrument_your_app_to_talk_to_the_emulators

Basically you want to start the functions emulator like this:

firebase emulators:start --only functions

And then in your Android app (on the same machine):

FirebaseFunctions.getInstance().useFunctionsEmulator("http://10.0.2.2:5001");

Of course this is an http endpoint not https so for apps targeting Android 8.0+ the platform will block this by default.

The simplest solution is to change this globally in your debug builds:

<application
    android:usesCleartextTraffic="true"

However if you're concerned about security you can set a more advanced per-host network security file:
https://developer.android.com/training/articles/security-config

Thanks! works now

Was this page helpful?
0 / 5 - 0 ratings