ark
ark

Reputation: 563

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!

Upvotes: 26

Views: 106393

Answers (16)

Ivan J. Lee
Ivan J. Lee

Reputation: 111

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.

Upvotes: 0

Fakhar Iqbal
Fakhar Iqbal

Reputation: 4069

Invalidate cache & restart the android studio works for me!

Upvotes: 0

Heshan Weerasooriya
Heshan Weerasooriya

Reputation: 49

Clear proxy setting at gradle.properties (Global properties)

Upvotes: 3

Aditi Anshu
Aditi Anshu

Reputation: 11

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

Upvotes: 1

Barungi Stephen
Barungi Stephen

Reputation: 847

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.

Upvotes: 1

Chris Claude
Chris Claude

Reputation: 1372

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

Upvotes: 10

Glenn Michael Mejias
Glenn Michael Mejias

Reputation: 43

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

Upvotes: 2

P.Iravani
P.Iravani

Reputation: 39

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.

Upvotes: 2

Edalat Feizi
Edalat Feizi

Reputation: 1401

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

Upvotes: 1

anant vikram singh
anant vikram singh

Reputation: 21

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

Upvotes: 1

Siddhi Rajput
Siddhi Rajput

Reputation: 21

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.

Upvotes: 2

Mahdi-Malv
Mahdi-Malv

Reputation: 19220

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

Upvotes: 4

diewland
diewland

Reputation: 1915

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

Upvotes: 11

bibspark
bibspark

Reputation: 241

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.

Upvotes: 24

P.Sierpinski
P.Sierpinski

Reputation: 121

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

Upvotes: 12

jtdressel
jtdressel

Reputation: 166

I think it's a network issue. My project currently fails to build unless I pass the --offline argument to gradle. I think the S3 outage is impacting repos hosting dependencies.

Try ./gradlew tasks --offline

Or, to make android studio run in offline mode, follow the instructions: https://stackoverflow.com/a/32173577/1043518

Upvotes: 15

Related Questions