I'm trying to use firebase as backend of my android application. But at this early stage it's too slow to deploy to google server and test every new functionality and every fix.
I wonder is it possible to run it locally so my android app can call onCall() functions on localhost:port ?
I've found some .useFunctionsEmulator('http://localhost:8080'); but I'm not sure what import do I need and how exactly to start local "server"
I'm trying to use firebase as backend of my android application. But at this early stage it's too slow to deploy to google server and test every new functionality and every fix.
I wonder is it possible to run it locally so my android app can call onCall() functions on localhost:port ?
I've found some .useFunctionsEmulator('http://localhost:8080'); but I'm not sure what import do I need and how exactly to start local "server"
Share Improve this question edited Nov 17, 2018 at 16:36 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Nov 17, 2018 at 15:50 Ivan PeshevIvan Peshev 4557 silver badges17 bronze badges 3- This is currently not supported. You will have to either deploy the function or test it in the emulator using the CLI. – Doug Stevenson Commented Nov 17, 2018 at 19:18
- Doug, What emulator do you have in mind ? Please give me some link where I can read about firebase emulator and running firebase app in it ? – Ivan Peshev Commented Nov 18, 2018 at 5:44
- firebase.google./docs/functions/… – Doug Stevenson Commented Nov 18, 2018 at 9:33
3 Answers
Reset to default 3When you start your Firebase Emulators with
firebase emulators:start
check the log messages to see where your Cloud Functions are running, e.g. functions: Emulator started at http://localhost:5001
.
You can access then call your function by using firebase.functions().useFunctionsEmulator('http://localhost:5001')
If you are testing on a real device you will have to replace localhost with the IP address of your PC, assuming that PC + device are connected to the same network.
If you are testing on Android Studio's device Emulator you will have to replace localhost with 10.0.2.2, since localhost will point the Emulator to its own localhost address and not your PC's.
This did the trick for me.
I just tested it has i had the same problem and had not found how to solve it because i had ran on outdated information i guess.
So, what i do from my REACT app
i added this line after initializing the firebase app with config:
app.functions().useFunctionsEmulator('http://localhost:5000')
and i use the mand "firebase serve" to start the local emulating process.
Note that 5000 is the default port you can change that by adding --port xxxx where xxxx is the port number.
For Android the function is clearly in the doc so i guess it should work too: https://developers.google./android/reference//google/firebase/functions/FirebaseFunctions
then if you would be testing on the device, meaning not your dev machine then it would not be localhost but the adresse of your machine or you could use ngrok to redirect port and use the temporary link they provide you.
You are looking for:
firebase.initializeApp(config);
firebase.functions().useFunctionsEmulator('http://localhost:5001')
Changing 'http://localhost:5001'
to whatever your emulator is set to run on