So, I’m working with Expo and React Native. I’m having problems trying to connect to my local API via http
from an Android device.
If I tried from the emulator using http://10.0.2.2:PORT_NUMBER
, it works, but I cannot develop the app from the emulator because I need several features that only a device can offer (camera, bluetooth, etc).
I tried the next that I found but they’re not working, except one using ngrok:
- Change URL localhost to 10.0.2.2 (only works in the emulator)
- Change the URL to my local IP 192.168.x.x. It does not work from my device, I can get access from the browser though.
- I already had the right configuration in the
app.json
:
...
[
"expo-build-properties",
{
"android": {
"usesCleartextTraffic": true
}
}
],
...
- ngrok: it was the only way to make it work, but because it uses
https
- I tried several public APIs but all of them are using
https
, so they’re working
My teammate does not have any problem running the same code but using an Ios device.
I think the solution should not be changing the local API to https
or use ngrok
, is it just impossible to connect via http
from an Android device?
Thank you in advance!