欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

解决 gradle 依赖库在中国无法下载问题的小窍门

最编程 2024-03-03 20:14:37
...

一般项目默认生成的配置
buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

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

由于google的原因,可能会下载慢甚至下载失败等各种问题。

好在阿里云有提供国内镜像,直接换国内,流畅得很。

阿里云镜像使用指南

最后更换的代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
       // google()
       // jcenter()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        

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

allprojects {
    repositories {
      //  google()
      //  jcenter()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
}

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

推荐阅读