gradle下载慢或者无法下载的问题的原因是服务器在国外,解决方法就是将下载网址改为国内的镜像网址。
1.将gradle-wrapper.properties这个文件中的distributionUrl后面的网址改为腾讯的镜像网址:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2.在settings.gradle.kts这个文件中google前添加上阿里云的镜像网址:
pluginManagement {
repositories {
// 使用阿里镜像源
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")
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// 使用阿里镜像源
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/central")
google()
mavenCentral()
}
}
之后点击右上方的Sync Now,等待Android Studio下载完毕即可。