'Ionic Capacitor running in android - CONNECTION_REFUSED

I'm trying to run my capacitor app in android, running through android studio - the app opens and says:

"Webpage not available - the webpage at "http://localhost:8100" could not be loaded because of ERR_CONNECTION_REFUSED"

and it's quite obvious that I can't access my app by navigating to http://localhost:8100 from my android device (only from the computer which is connected with wires), so I wonder how it should work..

Any idea?



Solution 1:[1]

OK so I just checked the ionic capacitor run command options docs and saw this:

--external
Description 
Host dev server on all network interfaces (i.e. --host=0.0.0.0)

Tried it... and it works.

running my app with:

ionic capacitor run android -l --external worked on the same wi-fi

Solution 2:[2]

What has worked for me was using the external URL provided by ionic to call my end-point instead of localhost

When I want to test on the emulator/device, I ran ionic capacitor run android --livereload --external

and then the console show me this enter image description here

so to call to my endpoint I used to do http://localhost:8080/api, instead, I must do http://xxx.xxx.x.xx:8080/api

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 CrsCaballero