Gradle sync failed “read time out“

在使用Android Studio进行开发时,经常会碰到以下问题:在Gradle进行Project Sync时由于需要从国外网站下载jar包文件,当下载发生中断时就会导致Sync失败。解决方法之一是使用国内阿里云镜像,具体步骤如下:

  1. 修改build.gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/'}
        maven { url 'https://maven.aliyun.com/repository/jcenter/'}
        mavenLocal()
        mavenCentral()

    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/'}
        maven { url 'https://maven.aliyun.com/repository/jcenter/'}
        mavenLocal()
        mavenCentral()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  1. 重新Sync工程

  2. 此外还可以通过修改文件gradle.properties中org.gradle.jvmargs来调整容许网络延时来提高Sync成功率

org.gradle.jvmargs=-Xmx1536m -Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.http.socketTimeout=120000
  1. Gradle配置指南参考阿里云网站。1

  1. https://help.aliyun.com/document_detail/102512.html?spm=a2c40.aliyun_maven_repo.0.0.36183054TojOuO ↩︎

对于 "android studio read timed out" 错误,可以尝试以下解决方法: 1. 检查网络连接:确保网络连接正常,尝试重新启动网络设备或连接到其他网络进行验证。 2. 检查防火墙和代理设置:如果你的网络使用了防火墙或代理服务器,确保 Android Studio 可以正常访问所需的网络资源。可以尝试禁用防火墙或代理,然后重新运行 Android Studio 进行测试。 3. 更新 Gradle 版本:如果你在使用 Gradle 构建项目时遇到问题,尝试更新 Gradle 版本。可以在项目根目录下的 `gradle/wrapper/gradle-wrapper.properties` 文件中修改 Gradle 版本号,然后重新同步项目。 4. 增加超时时间:可以通过修改 Android Studio 的默认超时时间来解决此问题。在 Android Studio 中打开设置,然后找到 "Build, Execution, Deployment" -> "Build Tools" -> "Gradle"。在 "Gradle build" 部分,将 "Global Gradle settings" 中的 "Timeout (sec)" 值增加一些,然后点击应用并重新构建项目。 5. 清除缓存和重启:尝试清除 Android Studio 的缓存并重启软件。可以通过选择 "File" -> "Invalidate Caches / Restart" 来执行此操作。 6. 检查依赖库镜像源:如果你在使用依赖库时遇到问题,可以尝试更改依赖库的镜像源。在项目的 `build.gradle` 文件中,将依赖库的地址更改为其他可靠的镜像源。 如果以上方法仍然无法解决问题,请提供更多错误信息和具体的操作步骤,以便提供更准确的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值