Android Gradle 配置阿里云Maven镜像地址

2,048 阅读1分钟

阿里云Mvn仓库地址:仓库服务 (aliyun.com)

Android 需要的maven库地址:

https://maven.aliyun.com/repository/public/
https://maven.aliyun.com/repository/central
https://maven.aliyun.com/repository/google
https://maven.aliyun.com/repository/gradle-plugin

因为JCenter已经停止服务,所以原JCenter已经迁移到了Central

image.png

基于Gradle 8.4.1构建的项目 在项目根目录下找到settings.gradle.kts 在pluginManagement、dependencyResolutionManagement的repositories下添加

//添加阿里云镜像
maven(url = "https://maven.aliyun.com/repository/public/")
maven(url = "https://maven.aliyun.com/repository/central")
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/gradle-plugin")

该文件为kts,kotlin语言,所以maven是一个方法,写法maven(url="") url为参数

完整配置如下:

pluginManagement {
    repositories {
        //添加阿里云镜像
        maven(url = "https://maven.aliyun.com/repository/public/")
        maven(url = "https://maven.aliyun.com/repository/central")
        maven(url = "https://maven.aliyun.com/repository/google")
        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/public/")
        maven(url = "https://maven.aliyun.com/repository/central")
        maven(url = "https://maven.aliyun.com/repository/google")
        maven(url = "https://maven.aliyun.com/repository/gradle-plugin")
        google()
        mavenCentral()
    }
}

rootProject.name = "android-template"
include(":app")


如有问题,欢迎评论指正,感谢!!!