5

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?

4 Answers 4

19

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

Sign up to request clarification or add additional context in comments.

2 Comments

Lol, My phone and laptop are on the same LAN, running it with external tag, and it still isn't working. It's showing ERR_ADDRESS_UNREACHABLE. Is it an issue with Capacitor or my LAN ?
"ionic capacitor run android -l --external" is the answer. That's how I got it working on iOS, than for some reason, Ionic Official Docs had the same step for Android with a slightly different other command, which only worked the 1st time: "ionic capacitor run android -l --host=YOUR_IP_ADDRESS"
1

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

Comments

1

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

Comments

0

Forwarding the respective port worked for me e.g. cap run android --forwardPorts 5173:5173

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.