build报错
> Task :app:checkDebugAarMetadata FAILED Execution failed for task ':app:checkDebugAarMetadata'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.> Could not resolve com.blankj:utilcode:1.25.8.Required by:project :app> Could not resolve com.blankj:utilcode:1.25.8.> Could not get resource 'https://repo.maven.apache.org/maven2/com/blankj/utilcode/1.25.8/utilcode-1.25.8.pom'.> Could not HEAD 'https://repo.maven.apache.org/maven2/com/blankj/utilcode/1.25.8/utilcode-1.25.8.pom'.> Connection reset
我先查看项目的 build.gradle 与 gradle.properties,确认当前的仓库配置,然后会把仓库替换为国内镜像(阿里云/华为/清华)以解决 Maven Central 连接重置问题。接着我会保存并建议重新构建。
我将把顶层 build.gradle 的仓库源添加国内镜像(阿里云/华为)到 buildscript 和 allprojects 的 repositories,以解决 Maven Central 连接重置导致的依赖下载失败。接下来我会保存这些编辑。
我已在顶层 build.gradle 中为 buildscript 和 allprojects 的 repositories 添加了阿里云与华为的国内镜像,并保留官方源作为兜底,这能解决 com.blankj:utilcode:1.25.8 因 Maven Central 连接重置导致的下载失败问题。
项目的build.gradle修改结果如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {repositories {// 优先使用国内镜像,加速依赖解析maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/repository/public' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url 'https://repo.huaweicloud.com/repository/maven' }// 兜底官方源(网络可达时使用)google()jcenter()mavenCentral()}dependencies {classpath 'com.android.tools.build:gradle:4.1.3'//classpath 'com.android.tools.build:gradle:3.2.1'//classpath 'com.android.tools.build:gradle:3.1.4'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files} }allprojects {repositories {// 优先使用国内镜像maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/repository/public' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url 'https://maven.aliyun.com/repository/jcenter' }maven { url 'https://repo.huaweicloud.com/repository/maven' }// 第三方仓库maven { url = 'https://jitpack.io' }// 兜底官方源google()jcenter()mavenCentral()} }task clean(type: Delete) {delete rootProject.buildDir }
接下来请按下面顺序重试构建(Windows PowerShell):
1) 停掉 Gradle 守护进程
.\gradlew --stop
2) 强制刷新依赖并构建
.\gradlew clean assembleDebug --refresh-dependencies -x test
若仍有网络波动:
临时清缓存后再试(可能会慢)
rd /s /q %USERPROFILE%\.gradle\caches .\gradlew clean assembleDebug --refresh-dependencies -x test
或配置代理后再试(如有可用的公司代理)
状态更新:
我已将国内镜像源加入 build.gradle 的仓库配置。现在建议你执行上述构建命令验证依赖能否成功解析。