我正在尝试使用 firebase 作为我的 android 应用程序的后端。 但在这个早期阶段,部署到谷歌服务器并测试每个新功能和每个修复都太慢了。
我想知道是否可以在本地运行它以便我的 android 应用程序可以在 localhost:port 上调用 onCall() 函数?
我找到了一些 .useFunctionsEmulator(' http://localhost:8080 '); 但我不确定我需要什么导入以及如何启动本地“服务器”
最佳答案
当您启动 Firebase 模拟器时
firebase emulators:start
检查日志消息以查看您的 Cloud Functions 在哪里运行,例如功能:模拟器启动于 http://localhost:5001
。
您可以使用 firebase.functions().useFunctionsEmulator('http://localhost:5001')
如果您在真实设备上进行测试,您必须将 localhost 替换为 您 PC 的 IP 地址,假设 PC + 设备连接到同一网络。
如果您在 Android Studio 的设备模拟器 上进行测试,您必须更换 localhost 为 10.0.2.2,因为 localhost 会将模拟器指向它自己的 本地主机地址,而不是您的 PC。
这对我有用。
关于javascript - 如何在本地测试 firebase onCall()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53352821/