Android Studio: Gradle sync failed: Connection timed out: connect
Asked Answered
R

16

26

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!

Raff answered 28/2, 2017 at 18:24 Comment(4)
I have the same issue, very strangeZacek
I too facing same problemSignorelli
before trying any solution, use a proxy or vpn.Kingly
anybody has a solution, please hep me!Cankered
U
15

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://mcmap.net/q/243445/-how-to-configure-gradle-to-work-quot-offline-quot-using-cached-dependencies

Upbear answered 28/2, 2017 at 19:21 Comment(1)
I guess you're right, going offline fixed it. I guess some of my gradle dependencies are affected from the outage that you're talking about.Raff
B
24

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.

Bluegill answered 10/4, 2017 at 21:37 Comment(1)
Same issue happened to me , Resolved just by following this method .Also make sure that No proxy is selected in to File --> Settings -->System Settings --> HTTP Proxy .Siddons
U
15

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://mcmap.net/q/243445/-how-to-configure-gradle-to-work-quot-offline-quot-using-cached-dependencies

Upbear answered 28/2, 2017 at 19:21 Comment(1)
I guess you're right, going offline fixed it. I guess some of my gradle dependencies are affected from the outage that you're talking about.Raff
M
12

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

Mcclanahan answered 10/3, 2017 at 0:25 Comment(0)
P
11

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
Philippi answered 18/8, 2017 at 8:56 Comment(2)
He is not using any proxy.Caylacaylor
@AntonMalmygin my mistake, sorry.Philippi
F
10

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

Ferrick answered 16/3, 2019 at 13:45 Comment(1)
Thanks, had the exact same issue, seems that when i installed android studio back in 2018 it had used the proxy, forgot about it when I started working on this machine again recently.Already
M
4

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
Muffle answered 6/7, 2018 at 20:42 Comment(0)
L
3

Clear proxy setting at gradle.properties (Global properties)

Lavella answered 20/8, 2020 at 11:19 Comment(0)
F
2

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.

Fly answered 17/8, 2018 at 10:10 Comment(0)
P
2

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.

Prudish answered 20/10, 2018 at 7:7 Comment(1)
From Review: Hi, this post does not seem to provide a quality answer to the question. Please either edit your answer and improve it, or just post it as a comment.Tourism
W
2

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

Willamina answered 6/12, 2018 at 7:49 Comment(0)
H
1

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

Hiles answered 22/8, 2018 at 0:21 Comment(0)
G
1

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

Germanism answered 12/9, 2018 at 4:52 Comment(0)
D
1

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.

Donothing answered 16/10, 2019 at 7:52 Comment(0)
A
1

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

Amorette answered 4/7, 2020 at 4:35 Comment(0)
C
0

Invalidate cache & restart the android studio works for me!

Centiliter answered 22/10, 2020 at 5:21 Comment(0)
S
0

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.

Substantialism answered 18/5, 2022 at 3:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.