当前位置: 移动技术网 > 移动技术>移动开发>Android > Gradle sync failed “read time out“

Gradle sync failed “read time out“

2020年07月08日  | 移动技术网移动技术  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网