方法一

1. 配置根目录的setting.gradle.kts文件

pluginManagement {repositories {maven { url=uri ("https://www.jitpack.io")}maven { url=uri ("https://maven.aliyun.com/repository/releases")}maven { url=uri ("https://maven.aliyun.com/repository/google")}maven { url=uri ("https://maven.aliyun.com/repository/central")}maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")}maven { url=uri ("https://maven.aliyun.com/repository/public")} google()mavenCentral()gradlePluginPortal()}}dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {maven { url=uri ("https://www.jitpack.io")}maven { url=uri ("https://maven.aliyun.com/repository/releases")}maven { url=uri ("https://maven.aliyun.com/repository/google")}maven { url=uri ("https://maven.aliyun.com/repository/central")}maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")}maven { url=uri ("https://maven.aliyun.com/repository/public")}google()mavenCentral()}} rootProject.name = "test1"include(":app")

2. 配置http 代理

腾讯: https://mirrors.cloud.tencent.com/AndroidSDK/阿里: https://mirrors.aliyun.com/android.googlesource.com/##可以都试一下

方法二

配置对所有项目起效的项目环境

查看.gradle所在位置 :打开Android Studio->File->setting

打开你的.gradle文件,然后新建init.gradle

allprojects{repositories {def MY_ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'def MY_ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'all { ArtifactRepository repo ->if(repo instanceof MavenArtifactRepository){def url = repo.url.toString()if (url.startsWith('https://repo1.maven.org/maven2')) {project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith('https://jcenter.bintray.com/')) {project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_JCENTER_URL."remove repo}}}maven {url MY_ALIYUN_REPOSITORY_URLurl MY_ALIYUN_JCENTER_URL}}}