这个问题,有一种情况是网络不通的问题。
将访问地址修改为国内镜像即可解决:
在 settings.gradle 的repositories闭包中添加:
pluginManagement {
repositories {
maven { url "https://jitpack.io" }
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url "https://jitpack.io" }
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
google()
mavenCentral()
}
}
这篇博客主要介绍了如何解决Gradle在构建过程中因网络问题无法访问国外仓库的困境。通过将仓库地址替换为国内镜像,如阿里云仓库,可以确保Gradle能够顺利下载依赖。在settings.gradle文件中,你需要添加多个国内镜像源,包括阿里云的 releases、jcenter、google等仓库,以确保所有依赖的完整覆盖。这样做不仅可以提高构建速度,还能避免因网络不稳定导致的构建失败。
1万+

被折叠的 条评论
为什么被折叠?



