'Android Studio: Gradle sync failed: Connection timed out: connect

My Android Studio was working fine till morning, but since tonight I get error saying "Gradle sync failed: Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.". I am not using any proxy server. Even the option for HTTP proxy is set to "no proxy". I have no idea how to get this working. I tried giving public access to Android Studio in firewall but it didn't work.

Any help/solution is welcome.

P.S. My Android Studio version is 2.2.3

Thank you!



Solution 1:[1]

I copied a project that was created else where. After removing these proxy credentials:

systemProp.http.proxyPassword=your_password

systemProp.http.proxyHost=host_Ip_address

systemProp.http.proxyUser=your_username

systemProp.http.proxyPort=port_number

in the gradle.properties, it worked like a charm.

Solution 2:[2]

For me it was the firewall. Definitely, only that. After adding Android Studio to it's whitelist everything is working like a charm.

Solution 3:[3]

Do not forget proxy for https in gradle.properties

systemProp.http.proxyHost=your.proxy.host
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password
#
# DO NOT forget https proxy, too!
#
systemProp.https.proxyHost=your.proxy.host
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password

Solution 4:[4]

I got the very same problem.

In my case, I started my android project on campus. Everything was fine then. When came home and started using the wifi I got the same problem (Gradle sync failed: Connection timed out).

All did is modify gradle.properties file under Gradle Scripts. I just removed the proxy settings that were stored in that file. Everything's back to normal now.

Below is an image of where to find the file:

Finding gradle.properties in your project

Solution 5:[5]

If your Proxy settings is set to No Proxy [Based on how i solved this issue in my case] check out gradle.properties (Global properties) and clear proxy lines.

#systemProp.https.proxyPort=port
#systemProp.http.proxyHost=proxy
org.gradle.jvmargs=-Xmx2048m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8 -Djava.net.preferIPv4Stack\=true
org.gradle.daemon=true
#systemProp.https.proxyHost=proxy
org.gradle.configureondemand=false
#systemProp.http.proxyPort=port
android.enableBuildCache=true

Solution 6:[6]

Clear proxy setting at gradle.properties (Global properties)

Solution 7:[7]

It can be a network issue sometimes. You can try to resolve it by turning off your "Firewall Protection". Also you need to turn off Firewall Protection from Antivirus.

Solution 8:[8]

There are several countries that their IP's are blocked by Android Studio so if you feel your IP is one of them just simply connect to a VPN service.

Solution 9:[9]

I solved my problem by turning off my anti-virus (avast)

Solution 10:[10]

If proxy settings are correct then go to file and click on "Invalidate Caches/Restart..." to invalidate the cache and restart android studio.

Solution 11:[11]

I solved it by executing cleanBuildCache in android studio

open Gradle projects tab in the right top corner of android studio under build folder double click on cleanBuildCache and then run you project

enter image description here

Solution 12:[12]

This may also happen when you don't have an internet connection on the network you are connected to . the fix would be to easily get a proper internet connection and re-sync Gradle.

Solution 13:[13]

What worked for me was removing the port settings from the Gradle.properties file. I wasn't using any proxy and that resulted in the mismatch. I commented out the following lines

systemProp.https.proxyPort=your_port

systemProp.http.proxyHost=your_proxy

Solution 14:[14]

Invalidate cache & restart the android studio works for me!

Solution 15:[15]

In my situation, I use a proxy. The right way to make it work is to turn on proxy first and then launch Android Studio.