问题
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!
回答1:
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
回答2:
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.
回答3:
For me it was the firewall. Definitely, only that. After adding Android Studio to it's whitelist everything is working like a charm.
回答4:
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
回答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
回答6:
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:
回答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.
回答8:
I solved my problem by turning off my anti-virus (avast)
回答9:
If proxy settings are correct then go to file and click on "Invalidate Caches/Restart..." to invalidate the cache and restart android studio.
回答10:
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
回答11:
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.
回答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.
来源:https://stackoverflow.com/questions/42516117/android-studio-gradle-sync-failed-connection-timed-out-connect