当前位置:   article > 正文

Android Studio : Read timed out和connect timed out的解决方法_安卓connect timed out

安卓connect timed out

科学上网也无法自动下载gradle,导致跨大版本升级As(Android Studio),出现各种问题。

目前来说,不考虑架构,插件等的问题。一进来就给你个build半天。

方法除了gradle指定。gradle下载覆盖C盘 .gradle的wrapper里面的文件夹对应的gradle版本。

还有一个就是依赖库,插件下载缓慢,Gradle:Build model问题。

本来不想写博文的。但是有时候同一个方法有多重解决方法。得记录下,分享出去,别人也不一定是同方法解决同问题,就是这么神奇。

------------------------------------------- 正文 --------------------------------------------

Cause: Read timed out的解决方法
第一步:(可有可无,有了可能对于构建速度会加快些)

修改文件gradle.properties

路径:在C:\Users\用户名(一般是Administrator,或者你自己定义的用户名) 文件下的.gradle/gradle.properties文件

1、开启daemon: 在上述文件中加入下面的代码

org.gradle.daemon=true
  • 1

2、设置并行构建

org.gradle.parallel=true
  • 1
第二步:

由于gradle7.0版本,构建参数放在不同的文件中。

gradle7.0前的版本:

项目根目录下:build.gradle中,在buildscript的repositories中,和allprojects的repositories中都切换成以下代码,注释掉mavenCentral,和google那两行。

    //mavenCentral()
    // google()
    maven { url 'https://maven.aliyun.com/repository/google' } 
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }                                                                                                  
  • 1
  • 2
  • 3
  • 4
  • 5

gradle7.0以后的版本:

pluginManagement {
    //构建依赖库仓配置
    repositories {
         //mavenCentral()
        // google()
        maven { url 'https://maven.aliyun.com/repository/google' } 
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } 
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

然后重新build gradle。

AS的工具栏:File->Sync Project with Gradle Files

注意
Cause: connect timed out的解决方法

而且AS不报其他错误。不过,如果你有足够的时间,在build多次后,build栏就会出现除timed out 的另外一条错误:Could not resolve com.android.tools.build:gradle:x.x.x。

1、先在As的项目的根目录gradle\wrapper\gradle-wrapper.properties 中的gradle地址(https://services.gradle.org/distributions/gradle-x.x.x-bin.zip)的在浏览器手动下载gradle

2、下载gradle包后,校验sha256

1、按下快捷键 Win + R , 并输入cmd 按下回车键。

2、certutil -hashfile C:\xxxx\xxx\gradle-x.x.x-bin.zip sha256

3、去https://gradle.org/release-checksums/#v7.5 对比sha值。
或者直接在下载地址 gradle-x.x.x-bin.zip.sha256  这里下载下来对比。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3、将文件 gradle-x.x.x-all.zip 复制到 C:\Users\Administrator.gradle\wrapper\dists\gradle-x.x.x-all.zip\aababccxxdsd 文件夹下,无需解压,其中 aababccxxdsd 文件每个人的可能不一样。

然后重新build。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/317264?site
推荐阅读
相关标签
  

闽ICP备14008679号