Android项目Gradle构建失败:JitPack依赖出现401未授权错误
问题现象
开发Android项目时,Gradle构建无法解析多个依赖项,部分来自JitPack的依赖返回401 Unauthorized错误,手动访问对应URL需输入用户名密码。
核心错误片段
> Could not resolve all files for configuration ':app:debugCompileClasspath'. > Could not find com.ankushgrover:Hourglass:2.0.0. > Could not find com.tbuonomo.andrui:viewpagerdotsindicator:4.1.2. > Could not resolve com.tonyodev.fetch2:fetch2:3.0.12. > Could not GET 'https://jitpack.io/com/tonyodev/fetch2/fetch2/3.0.12/fetch2-3.0.12.pom'. Received status code 401 from server: Unauthorized > Could not resolve com.github.barteksc:android-pdf-viewer:3.2.0-beta.1. > Could not GET 'https://jitpack.io/com/github/barteksc/android-pdf-viewer/3.2.0-beta.1/android-pdf-viewer-3.2.0-beta.1.pom'. Received status code 401 from server: Unauthorized
完整未找到依赖列表
com.github.alxrm:audiowave-progressbar:0.9.2com.github.mirrajabi:search-dialog:1.2.4com.github.denzcoskun:ImageSlideshow:0.0.7com.github.mukeshsolanki:Google-Places-AutoComplete-EditText:0.0.8com.github.jitenderdev:countryutility:v1.1com.github.judemanutd:autostarter:1.0.9com.github.denizsubasi:CCView:0.3com.github.hrskrs:InstaDotView:1.1com.asksira.android:loopingviewpager:1.1.2com.github.badoualy:stepper-indicator:1.0.7com.github.Justson:Downloader:v5.0.0-androidxcom.github.sharish:ShimmerRecyclerView:v1.3com.github.BelooS:ChipsLayoutManager:v0.3.7com.github.mancj:SlideUp-Android:2.2.8com.github.adrielcafe:AndroidAudioRecorder:0.3.0com.github.mmob-tech:mmob-client-android:v0.4.11com.github.smhdk:KM-Recyclerview-Sticky-Header:v1.0.0com.github.Gkemon:Android-XML-to-PDF-Generator:2.6.8com.github.BlacKCaT27:CurrencyEditText:2.0.2com.github.Prashant-Chandel:Videoplayer-with-Vimeo-support:138257e15ccom.github.martinstamenkovski:ARIndicatorView:2.0.0com.github.HamedTaherpour:ht-epub-reader-android:0.0.5com.library:library:1.0.0
排查与解决步骤
1. 检查JitPack仓库配置
确保项目根目录的build.gradle(或settings.gradle,Gradle 7+)中正确添加JitPack仓库,且无错误认证配置:
// Gradle 6及以下(根目录build.gradle) allprojects { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } } // Gradle 7+(settings.gradle) dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } }
若之前误给JitPack添加了不必要的credentials块,需直接移除。
2. 处理JitPack 401错误
JitPack返回401通常有两种原因:
- 私有仓库访问:如果依赖的是私有GitHub仓库,需在JitPack配置中添加GitHub个人访问令牌(PAT),令牌需开启
repo权限:maven { url 'https://jitpack.io' credentials { username = '你的GitHub用户名' password = '你的GitHub个人访问令牌' } } - JitPack构建失败:公开仓库可能因构建缓存或服务问题无法访问,可手动查看对应依赖的JitPack页面,若显示构建失败,点击「Retry」重新触发构建。
3. 验证依赖有效性
对所有Could not find的依赖逐一确认:
- 检查Group、Artifact、Version拼写是否正确,部分依赖可能已迁移到Maven Central等其他仓库。
- 确认对应的GitHub仓库是否存在、未被删除或改名。
- 核实版本号是否真实存在,部分旧版本可能已被作者移除。
- 对于
com.library:library:1.0.0这类无明确仓库标识的依赖,需确认其来源仓库是否已添加到项目配置中。
4. 清理Gradle缓存
执行命令清理本地缓存,避免缓存的错误依赖信息干扰构建:
# Windows gradlew clean build --refresh-dependencies # macOS/Linux ./gradlew clean build --refresh-dependencies
5. 检查网络与代理
- 若使用代理,确保Gradle代理配置正确,且代理可正常访问JitPack等仓库地址。
- 尝试切换网络(如从公司内网切换到个人网络),排除防火墙拦截的可能。
内容的提问来源于stack exchange,提问作者IamVariable
相关产品推荐
相关产品推荐

