You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行./gradlew app:dependencies报错:Could not resolve all files for ':classpath'

解决Gradle ":classpath" 依赖解析失败问题

针对你运行./gradlew app:dependencies时出现的Could not resolve all files for configuration ':classpath'错误,结合你的build.gradle配置,给出以下针对性解决方案:

1. 替换Beta版Kotlin插件为稳定版

你当前使用的Kotlin插件是1.8.20-Beta,Beta版本可能存在兼容性或下载源不稳定问题。将根目录build.gradle中的Kotlin插件版本改为与AGP 7.4.0兼容的稳定版(比如1.8.10):

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}

2. 确保Gradle版本与AGP兼容

AGP 7.4.0要求Gradle版本至少为7.5。检查gradle/wrapper/gradle-wrapper.properties中的distributionUrl,修改为对应版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

3. 补充仓库配置(关键)

你的根目录build.gradle缺少仓库配置,导致Gradle无法下载classpath所需的插件依赖。推荐在settings.gradle中统一配置仓库(Gradle 7+标准方式):

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        // 网络访问缓慢时,可添加国内镜像
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}
rootProject.name = "你的项目名称"
include ':app'

4. 清理缓存并重新同步

  • 运行命令强制刷新依赖:
./gradlew clean build --refresh-dependencies
  • 若仍有问题,手动删除本地Gradle缓存目录:
    • macOS/Linux: ~/.gradle/caches
    • Windows: C:\Users\<你的用户名>\.gradle\caches

5. 检查网络连接

确保网络可正常访问Google Maven和Maven Central,若处于网络受限环境,务必启用步骤3中的国内镜像源。

完成以上步骤后,重新运行./gradlew app:dependencies即可正常生成依赖树,方便排查嵌套依赖冲突。

内容的提问来源于stack exchange,提问作者Adam Varhegyi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 00:52:46