Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic emulate android ERR_CONNECTION_REFUSED localhost:8100

I try to emulate my Ionic application on Android. Once my application start in the emulated device, it breaks with the following error:

Application Error

net::ERR_CONNECTION_REFUSED (http://localhost:8100)

and also

Webpage not available

The webpage at http://localhost:8100 could not be loaded because: net::ERR_CONNECTION_REFUSED

Debugging same project works like a charm in browser and in iOS debugger.

cordova-plugin-whitelist is already installed and I have the following rule in my config.xml

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

Any help would be appreciated.

like image 705
David Dal Busco Avatar asked May 31 '16 15:05

David Dal Busco


4 Answers

I found the solution, I was running the command

ionic run android -c -s -l --address localhost

Removing --address localhost from the command solve my problem means following command is ok

ionic run android -c -s -l

Quite funny, since adding that parameter, let me run my App in the iOS debugger respectively in case of iOS was a must.

like image 178
David Dal Busco Avatar answered Nov 16 '22 10:11

David Dal Busco


You might want to try running

adb reverse tcp:8100 tcp:8100

Especially in case its a new device / emulator, so that port forwarding gets set up.

like image 33
Nik Barres Avatar answered Nov 16 '22 11:11

Nik Barres


Using the following command solve the issue for me on ionic 5 with capacitor

ionic capacitor run android -l --address 0.0.0.0
like image 40
Bassirou Diaby Avatar answered Nov 16 '22 11:11

Bassirou Diaby


The only solution I've got was to use my machine IP address instead of localhost for the API call

e.g.

NOK API endpoint: 'http://localhost:3002/api/'

OK API endpoint: 'http://192.168.1.XXX:3002/api/'

like image 1
RicardoVallejo Avatar answered Nov 16 '22 10:11

RicardoVallejo