欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Gradle sync failed “read time out“

程序员文章站 2022-03-12 09:17:57
在使用Android Studio进行开发时,经常会碰到以下问题:在Gradle进行Project Sync时由于需要从国外网站下载jar包文件,当下载发生中断时就会导致Sync失败。解决方法之一是使用国内阿里云镜像,具体步骤如下:修改build.gradle文件:// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { r...

在使用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 ↩︎

本文地址:https://blog.csdn.net/eaglecoder/article/details/107142429