解决:Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy

  • Post author:
  • Post category:其他



Android

2.0之后,出现该问题的原因是as访问https://services.gradle.org/distributions/gradle-xxx.zip下失败

如下:

  1. D:\Share_L\MyApplication>gradlew
  2. Downloading https://services.gradle.org/distributions/gradle-2.10-all.zip
  3. Exception in thread “main” java.net.ConnectException: Connection timed out: connect
  4. at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  5. at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
  6. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
  7. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  8. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  9. at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
  10. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  11. at java.net.Socket.connect(Socket.java:589)
  12. at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
  13. at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
  14. at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
  15. at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
  16. at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
  17. at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275)
  18. at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
  19. at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
  20. at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
  21. at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
  22. at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
  23. at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2661)
  24. at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2583)
  25. at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1769)
  26. at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
  27. at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
  28. at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
  29. at org.gradle.wrapper.Download.download(Download.java:44)
  30. at org.gradle.wrapper.Install





    1.call(Install.java:61)&nbsp;&nbsp;</span></li><li class=””><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.gradle.wrapper.Install




    1.call(Install.java:48)
  31. at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
  32. at org.gradle.wrapper.Install.createDist(Install.java:48)
  33. at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
  34. at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

D:\Share_L\MyApplication>gradlew
Downloading https://services.gradle.org/distributions/gradle-2.10-all.zip

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
        at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
        at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2661)
        at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2583)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1769)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
        at org.gradle.wrapper.Download.download(Download.java:44)
        at org.gradle.wrapper.Install$1.call(Install.java:61)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

解决方案:

1、settings->Build,Execution,Deployment->Build Tools->Gradle->Use local gradle distribution->Gradle home 指定gradle为本地已下载的gradle 如gradle-2.4


2、修改工程根目录下的build.gradle 中的 classpath 为 指定gradle版本以支持 上述中gradle home指定的gradle版本号 如:gradle-2.4 对应的 classpath 如下:

classpath 'com.android.tools.build:gradle:1.5.0'


3、在gradle->wrapper->gradle-wrapper.properties 将distributionUrl改为对应的gradle版本下载路径,如下:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.4.zip

4、Sync Project with Gradle Files

然后工程就复活了。

或者

systemProp.http.proxyHost=127.0.0.1

systemProp.http.proxyPort=8580

systemProp.https.proxyHost=127.0.0.1

systemProp.https.proxyPort=8580

gradle.properties里添加上述 试试看