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

Android项目Gradle构建失败:JitPack依赖出现401未授权错误

Android Gradle依赖解析失败(含JitPack 401 Unauthorized错误)

问题现象

开发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.2
  • com.github.mirrajabi:search-dialog:1.2.4
  • com.github.denzcoskun:ImageSlideshow:0.0.7
  • com.github.mukeshsolanki:Google-Places-AutoComplete-EditText:0.0.8
  • com.github.jitenderdev:countryutility:v1.1
  • com.github.judemanutd:autostarter:1.0.9
  • com.github.denizsubasi:CCView:0.3
  • com.github.hrskrs:InstaDotView:1.1
  • com.asksira.android:loopingviewpager:1.1.2
  • com.github.badoualy:stepper-indicator:1.0.7
  • com.github.Justson:Downloader:v5.0.0-androidx
  • com.github.sharish:ShimmerRecyclerView:v1.3
  • com.github.BelooS:ChipsLayoutManager:v0.3.7
  • com.github.mancj:SlideUp-Android:2.2.8
  • com.github.adrielcafe:AndroidAudioRecorder:0.3.0
  • com.github.mmob-tech:mmob-client-android:v0.4.11
  • com.github.smhdk:KM-Recyclerview-Sticky-Header:v1.0.0
  • com.github.Gkemon:Android-XML-to-PDF-Generator:2.6.8
  • com.github.BlacKCaT27:CurrencyEditText:2.0.2
  • com.github.Prashant-Chandel:Videoplayer-with-Vimeo-support:138257e15c
  • com.github.martinstamenkovski:ARIndicatorView:2.0.0
  • com.github.HamedTaherpour:ht-epub-reader-android:0.0.5
  • com.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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 02:23:16