新版本Android Studio的maven写法改变了,所以网上的老版本的修改gradle下载源的方法都无效了,改完会报错Unexpected tokens (use ';' to separate expressions on the same line)。
新的版本方法如下。
找到如下所示settings.gradle.kts。

打开后在两个地方添加如下代码

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

改完后这样。

pluginManagement {
    repositories {
        maven { url =uri("https://plugins.gradle.org/m2/")}
        maven { url =uri("https://maven.aliyun.com/nexus/content/repositories/google")}
        maven { url =uri("https://maven.aliyun.com/nexus/content/groups/public") }
        maven { url =uri("https://maven.aliyun.com/nexus/content/repositories/jcenter")}
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url =uri("https://plugins.gradle.org/m2/")}
        maven { url =uri("https://maven.aliyun.com/nexus/content/repositories/google")}
        maven { url =uri("https://maven.aliyun.com/nexus/content/groups/public") }
        maven { url =uri("https://maven.aliyun.com/nexus/content/repositories/jcenter")}
        google()
        mavenCentral()
    }
}

rootProject.name = "My Application"
include(":app")