Ionic 离子电容器在android中运行- CONNECTION_REFUSED

3mpgtkmj  于 2022-12-08  发布在  Ionic
关注(0)|答案(3)|浏览(176)

我试图在Android中运行我的电容器应用程序,通过Android Studio运行-应用程序打开并说:

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

很明显,我不能从我的安卓设备(只能从有线连接的电脑)导航到http://localhost:8100来访问我的应用程序,所以我想知道它应该如何工作。
你知道吗?

cqoc49vn

cqoc49vn1#

OK so I just checked the ionic capacitor runcommand 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

epfja78i

epfja78i2#

对我有效的方法是使用ionic提供的外部URL来调用我的端点,而不是使用localhost
当我想在模拟器/设备上进行测试时,我运行了ionic capacitor run android --livereload --external
然后控制台显示

因此,为了调用我的端点,我过去常常执行http://localhost:8080/api,而现在必须执行http://xxx.xxx.x.xx:8080/api

zaqlnxep

zaqlnxep3#

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

相关问题