Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 781
chrome Avatar asked Jul 30 '18 20:07

chrome


3 Answers

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

like image 133
Satinderpal Singh Avatar answered Oct 11 '22 07:10

Satinderpal Singh


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 [email protected]

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

like image 3
janpio Avatar answered Oct 11 '22 07:10

janpio


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 [email protected]
  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 [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
like image 3
Evan MJ Avatar answered Oct 11 '22 07:10

Evan MJ