Gradle无法解析指定第三方依赖问题求助(已做常规排查)
问题解决:Gradle无法解析指定依赖
错误日志
Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'. > Could not resolve all files for configuration ':app:debugCompileClasspath'. > Could not find com.github.warkiz.widget:indicatorseekbar:2.1.0. Required by: project :app > Could not find com.kyleduo.switchbutton:library:1.4.6. Required by: project :app > Could not find us.belka:androidtoggleswitch:1.2.2. Required by: project :app
当前根目录build.gradle配置
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() } dependencies { // Do not place your application dependencies here. // They belong in the individual module build.gradle files. classpath 'com.android.tools.build:gradle:7.1.3' classpath 'com.google.gms:google-services:4.3.10' classpath 'io.realm:realm-gradle-plugin:10.4.0' } } allprojects { repositories { mavenCentral() // maven { url "https://jitpack.io" } jcenter() // Warning: this repository is going to shut down soon google() } } task clean(type: Delete) { delete rootProject.buildDir }
已执行的排查操作
- 仓库配置检查:尝试添加google()、mavenCentral()、maven { url 'https://jitpack.io' }以确保依赖可访问
- 关闭离线模式:确认Gradle离线模式已关闭,允许从网络拉取依赖
- 清理Gradle缓存:删除项目根目录及用户主目录下的.gradle文件夹,移除可能损坏的缓存文件
- 验证依赖版本:确认三类依赖的版本指定正确且应为可用状态
- 同步Gradle文件:完成修改后执行Android Studio的Gradle文件同步操作
问题原因及解决方案
核心原因
你提到已尝试添加JitPack仓库,但当前配置里maven { url "https://jitpack.io" }处于注释状态,而报错的三个依赖均托管在JitPack仓库,Gradle无法访问这些依赖的存储位置,导致解析失败。
修复步骤
- 启用JitPack仓库:在根目录build.gradle的
allprojects.repositories中取消JitPack仓库的注释,确保Gradle能访问该仓库:allprojects { repositories { google() mavenCentral() maven { url "https://jitpack.io" } jcenter() // 可考虑后续移除,该仓库已停止维护 } } - 同步并重新构建:点击Android Studio右上角的"Sync Project with Gradle Files"按钮,完成同步后执行Clean Project和Rebuild Project操作。
额外注意事项
- jcenter()仓库已正式停止维护,若后续出现其他依赖无法解析的问题,建议排查对应依赖是否已迁移至mavenCentral或其他活跃仓库。
- 若仍存在依赖解析问题,可检查网络环境是否能正常访问JitPack仓库,必要时尝试切换网络或配置代理(若适用)。
内容的提问来源于stack exchange,提问作者ishara sewwandi
相关产品推荐
相关产品推荐

