Gradle 第三方依赖资源下载慢问题

参考《Gradle》

Gradle 下载慢问题

问题:打开下载的第三方项目,下载其它版本 Gradle 时速度很慢

原因:Android Studio 中默认下载 Gradle 地址为 http://services.gradle.org/distributions/ ,该资源下载很慢

解决:

  • 修改项目 gradle > wrapper > gradle-wrapper.properties 文件中 distributionUrl 地址为本地已有的版本,可能存在版本不适配的问题,例如项目要求 gradle 版本必须为当前配置或以上「一般不推荐

  • 项目 build.gradle,注释掉 jcenter () ,改为阿里云的 maven 库地址。需要修改 buildscript 和 allprojects 的 repositories 「推荐」

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

    repositories {
    maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    google()
    // jcenter()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:4.1.1'


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

    allprojects {
    repositories {
    maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    google()
    // jcenter()
    }
    }

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

Gradle 设置

image-20211022112532901