完美解决Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy
发布于 2022-09-07    12,190 次阅读
当你用Android studio 打开一个新项目(一般是下载的工程),可能会报错 Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle. android 2.0以后,涌现该题目的缘由是as拜访...

当你用Android studio 打开一个新项目(一般是下载的工程),可能会报错 Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.

android 2.0以后,涌现该题目的缘由是as拜访https://services.gradle.org/distributions/gradle-xxx.zip下失败
解决方案:
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

然后工程就可以用了,问题完美解决了。