Ionic Capacitor running in android - CONNECTION_REFUSED

Viewed 3862

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?

3 Answers

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

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

Just another answer for someone who may encounter the problem the way I faced it:

On my computer (Windows 10) the issue was that a connection from the phone to my computer was not allowed. My network connection was configured with a guest/public profile and it did not have network detection on. I fixed this by:

  1. navigating to Start -> Settings -> Network and internet -> Wi-Fi tab ->Manage know networks -> select the network you are connected to -> click properties -> set network profile to private
  2. navigating to control panel ->Network and internet -> network center -> advanced settings for sharing (on the left) -> check that network detection is on for your selected profile (private)

ionic cap run android -l --external displays the app on the phone now

Related