安卓 · 2024年11月19日

Android studio Gradle及依赖 下载慢

Gradle是安卓构建器,但是因为网速问题,下载要么连接不上,要么下载非常慢;遇到这种需要调整下载地址; 找到项目目录下的gradlew; 修改distributionUrl等号后的路径;后面的版本根据自己的需要选择

# 原来的
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
# 调整后的
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.2-bin.zip
JavaScript

更改依赖( java格式)

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()
        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()
    }
}

rootProject.name = "Demo"
include(":app")
JavaScript

更改依赖( kts格式)

pluginManagement {
    repositories {
        // 使用阿里镜像源
        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") }
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        // 使用阿里镜像源
        maven { url = uri("https://maven.aliyun.com/repository/google") }
        maven { url = uri("https://maven.aliyun.com/repository/central") }
        google()
        mavenCentral()
    }
}

rootProject.name = "Demo"
include(":app")
 
JavaScript
源库阿里云的镜像地址
google()https://maven.aliyun.com/repository/google
mavenCentral()https://maven.aliyun.com/repository/central
gradlePluginPortal()https://maven.aliyun.com/repository/gradle-plugin