Ionic 2 - Error : net::ERR_CONNECTION_TIMED_OUT when run on android device

Viewed 10206

(Sorry for my bad English)

I have built an application with Ionic 2 for Android. In this application I need to get information from an API and it's works perfectly when I run do it in the browser (ionic serve).

The problem is when I run on my device (Android 6.0.1) I get this issue :

net::ERR_CONNECTION_TIMED_OUT

Then I searched how to resolve this and I tried many things.

I have the cordova-plugin-whitelist and my config.xml looks like :

<content src="index.html" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" subdomains="true" />

and I put this in my index.html :

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * data: 'unsafe-inline'; connect-src * 'unsafe-inline'; frame-src *; media-src *;">

I have read many documentation concerning this issue but I didn't find anything really helpful.

Can someone help me please ?

Thanks

6 Answers

Ionic 4 Solution(100% working):

  • run command - ionic serve --devapp

  • Go to - "Windows defender Security Center" in Windows 10. Disable your domain, private & public networks in the firewall.

  • Also, "Clear all app data" in your devApp (option in side nav bar).

Enjoy live-reloading of your new app in the real device!

In Ubuntu this issue may be sometimes related to the firewall. I had this issue and tried everything but nothing worked. At last i disabled my ubuntu's firewall and it worked like a charm. In ubuntu, UFW is the default firewall.
You can disable it by: sudo ufw disable
Check its status: sudo ufw status
Enable it later on: sudo ufw enable

(Be sure to keep the device and the system in the same network) Hope this helps, as it helped me.

On windows, it's a firewall issue. Disabling firewall works but it's not recommended. Just add Node.js in firewall exceptions.

Related