useFunctionsEmulator doesn’t work on real device

After quite a while trying to figure out why my android device couldn’t connect to my functions emulator on local host I finally traced through the code and found this section:

if (isAndroid && _origin) {
if (_origin.startsWith(‘http://localhost’)) {
_origin = _origin.replace(‘http://localhost’, ‘http://10.0.2.2’);
}
if (_origin.startsWith(‘http://127.0.0.1’)) {
_origin = _origin.replace(‘http://127.0.0.1’, ‘http://10.0.2.2’);
}

Which will work great for emulators, but breaks real devices since 10.0.2.2 is only within emulators. So ideally, you only want to run this code if it is running within an Android Emulator. Otherwise, if on a physical device it should be left as localhost and reverse proxied via

adb reverse tcp:5001 tcp:5001

1 possible answer(s) on “useFunctionsEmulator doesn’t work on real device

useFunctionsEmulator doesn’t work on real device

After quite a while trying to figure out why my android device couldn’t connect to my functions emulator on local host I finally traced through the code and found this section:

if (isAndroid && _origin) {
if (_origin.startsWith(‘http://localhost’)) {
_origin = _origin.replace(‘http://localhost’, ‘http://10.0.2.2’);
}
if (_origin.startsWith(‘http://127.0.0.1’)) {
_origin = _origin.replace(‘http://127.0.0.1’, ‘http://10.0.2.2’);
}

Which will work great for emulators, but breaks real devices since 10.0.2.2 is only within emulators. So ideally, you only want to run this code if it is running within an Android Emulator. Otherwise, if on a physical device it should be left as localhost and reverse proxied via

adb reverse tcp:5001 tcp:5001

1 possible answer(s) on “useFunctionsEmulator doesn’t work on real device