25

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!

ark
  • 553
  • 2
  • 11
  • 19

16 Answers16

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.

bibspark
  • 241
  • 1
  • 2
  • 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 . – Adi Jul 18 '19 at 07:23
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://stackoverflow.com/a/32173577/1043518

Community
  • 1
  • 1
jtdressel
  • 166
  • 2
  • 5
  • 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. – ark Feb 28 '17 at 19:30
11

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

P.Sierpinski
  • 111
  • 5
10

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
diewland
  • 1,865
  • 5
  • 30
  • 41
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

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Chris Claude
  • 973
  • 12
  • 25
  • 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. – Marco Aug 04 '19 at 21:21
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
Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
3

Clear proxy setting at gradle.properties (Global properties)

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.

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.

P.Iravani
  • 39
  • 1
  • From Review: Hi, this post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer and improve it, or just post it as a comment. – sɐunıɔןɐqɐp Oct 20 '18 at 07:48
2

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

1

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

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
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

Edalat Feizi
  • 1,371
  • 20
  • 32
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.

Barungi Stephen
  • 759
  • 8
  • 13
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

Ahwar
  • 1,746
  • 16
  • 30
0

Invalidate cache & restart the android studio works for me!

Fakhar
  • 3,946
  • 39
  • 35
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.

Ivan J. Lee
  • 101
  • 8