'getting net::ERR_CONNECTION_REFUSED (http://localhost:8080) on android 4.4.2 version
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.
Solution 1:[1]
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
Solution 2:[2]
In case anyone is still not able to resolve this error,
- Find the compatible webview version which works for you and run the below commands:
cordova plugin rm cordova-plugin-ionic-webview
cordova plugin add [email protected]
- 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
- 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 [email protected] worked for me for the below cordova and android versions:
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
Android target : android-28
Android SDK Tools : 26.1.1
cordova-android : 8.1.0
Solution 3:[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.
Solution 4:[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.
Solution 5:[5]
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.
Solution 6:[6]
/android/CordovaLib/src/org/apache/cordova/engine/SystemWebViewClient.java
onReceivedError(WebView view, WebResourceRequest request,
WebResourceError error) {
super.onReceivedError(view, request, error);
if (error.getErrorCode() == WebViewClient.ERROR_CONNECT) { //net::ERR_CONNECTION_REFUSED
view.goForward();
return;
} else {
errorMessage();
}
}
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 | Satinderpal Singh |
| Solution 2 | |
| Solution 3 | James |
| Solution 4 | ZlobnyiSerg |
| Solution 5 | Pietro |
| Solution 6 | Faakhir |
