getting net::ERR_CONNECTION_REFUSED (http://localhost:8080) on android 4.4.2 version

倖福魔咒の 提交于 2020-12-25 03:58:05

问题


I build a simple ionic project from this tutorial.

It runs on Xiaomi Mix 2 phone (android version 8.0.0) and on browser without any problem. But when I deployed to the samsung note 2 (android version 4.4.2), it gives an application error with this message: net::ERR_CONNECTION_REFUSED (http://localhost:8080)

Why am I getting this error?

Any advice and suggestions will be appreciated.

Kemal.


回答1:


Your problem is caused by the cordova-plugin-ionic-webview plugin that is part of every new or updated Ionic app.

This used to apply only to iOS, where it replaced the UIWebView with WKWebView, but on July 23rd 2018 they released version 2.0 of the plugin, that also included changes to the webview used on Android.

The Android webview now uses a local webserver at localhost:8080 to show your app instead of requesting the files directly from the file system.

Unfortunately this change also included this bit in the documentation:

Requirements
- […]
- Android: Android 5.0+ and cordova-android 6.4+

So cordova-plugin-ionic-webview just doesn’t support Android earlier than 5.0 any more, which of course means your app will not work on Android 4.x.

One solution is to downgrade the plugin to the last version that supported Android 4.x:

ionic cordova plugin add cordova-plugin-ionic-webview@1.2.1

More elaborate information and alternative solutions:
https://ionic.zone/debug/ionic-and-android-4




回答2:


I faced the same problem in Android 4.4, Android 6.0 but not in Android 8.0. I just added this code in config.xml to allow the localhost.

<allow-navigation href="http://localhost:8080/*"/>

For more information please follow this link: WKWebView




回答3:


You are getting the error because every function and module in Android only works from a certain version on newer. It could be 4.4.3 and up, 5.0 and up, or even 8.0 and up. It just depends. This means if and when you deploy it you will be required to select a minimum version. There is nothing you can do to fix it other than trying on a newer version. You can also change the code completely to work with older modules.




回答4:


I've had same error even on new devices. After that, I've reinstalled cordova-plugin-ionic-webview plugin. Reinstallation upgraded plugin from 4.0.0 to 5.0.0 and added new line to config.xml:

<allow-navigation href="http://localhost:8100" sessionid="f8f1cc34" />

I'm still waiting for review, but hope this will help.




回答5:


In case anyone is still not able to resolve this error,

  1. Find the compatible webview version which works for you and run the below commands:
    cordova plugin rm cordova-plugin-ionic-webview
    cordova plugin add cordova-plugin-ionic-webview@4.1.3
  1. In case you're using ionic, install the ionic plugin wrapper. (Skip this if your project is not an ionic project)
    npm install @ionic-native/ionic-webview
  1. Finally do clean installation of the platform and plugins. Delete the plugins folder and run the following commands:
    cordova platforms remove android
    ionic cordova build android

Or, if you use ionic,

    ionic cordova platforms remove android
    ionic cordova build android

Additional information: Plugin version cordova-plugin-ionic-webview@4.1.3 worked for me for the below cordova and android versions:

Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Android target    : android-28
Android SDK Tools : 26.1.1
cordova-android   : 8.1.0



回答6:


I had this problem for days and all the solutions I found did not work.

Ionic recommends using Capacitor to build the app and not Cordova. With Cordova does not work, on the other hand with Capacitor it works fine.

In your app directory first delete the Android folder (if any) and the one in Platform / Android folder.

I used these commands in this order launched by Powershell while staying in the APP directory

ionic build

ionic capacitor add android

npx cap open android

The first command will create a www folder. If the last command give an error and does not open Android Studio, do it manually, (I recommend using 4.0 version). Open Android Studio → open folder, navigate to the folder named Android located in the folder in your APP and then it worked for me. In Android Sudio 4 make sure you have Gradle updated and the SDK loaded.



来源:https://stackoverflow.com/questions/51602082/getting-neterr-connection-refused-http-localhost8080-on-android-4-4-2-ver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!