问题
我们通常使用的maven库的配置大部分采用系统默认配置:
例如
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// 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
}
上面的google() 和jcenter() 是采用内置在Android Studio之中的下载链接.
http://jcenter.bintray.com/
https://maven.google.com/
会下载包括项目构建的gradle库,kotlin库,androidx库等等.
通常情况下国内访问没有问题.
但是如果你的宽带运营商不给力.
你会发现有时候访问不了.或者出现了超时.
解决
这个时候我们可以尝试切换到阿里云的镜像地址.
替换的是阿里云的最新的仓库.
库都是一样的.但是访问阿里的maven仓库的下载速度要高得多.
替换方式如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
maven{
url 'https://maven.aliyun.com/repository/google/'
}
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
maven{
url 'https://maven.aliyun.com/repository/google/'
}
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如果发现上面的链接地址过时.
可以查询阿里云的官网进行替换: https://maven.aliyun.com/mvn/guide
注意:
如果替换了,建议注释掉原有的google()和jcenter().
评论区