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

求助:无法找到androidx.tonyodev.fetch2:xfetch2:3.1.4依赖包问题

解决 Could not find androidx.tonyodev.fetch2:xfetch2:3.1.4 依赖问题

问题原因

androidx.tonyodev.fetch2:xfetch2:3.1.4 已从Jcenter仓库下架,直接升级到3.1.5/3.1.6版本无效的核心原因是:react-native-background-downloader 的依赖树中指定了该旧版本,Gradle会优先遵循依赖树的版本约定,而非直接使用你手动指定的新版本。

可行解决方案

1. 强制指定xfetch2有效版本

在项目根目录的 android/build.gradle 文件中添加版本强制规则,让Gradle忽略旧版本约束,直接使用可用的新版本:

configurations.all {
    resolutionStrategy {
        force 'androidx.tonyodev.fetch2:xfetch2:3.1.6'
        force 'androidx.tonyodev.fetch2:xfetch2-core:3.1.6'
        // 若项目中用到xfetch2的其他子模块,需同步添加强制规则
    }
}

2. 修改依赖库的配置文件

直接修改 react-native-background-downloader 的依赖配置:

  • 定位到项目内 node_modules/react-native-background-downloader/android/build.gradle 文件
  • 将其中依赖的 xfetch2 版本从3.1.4替换为3.1.6
  • 执行 ./gradlew clean 清理构建缓存后重新构建项目

3. 确保仓库源配置正确

Jcenter已停止维护,需确保项目仓库配置中包含mavenCentral(多数迁移后的包托管在此):

allprojects {
    repositories {
        mavenCentral()
        google()
        // 保留项目所需的其他仓库源
    }
}

验证步骤

  1. 执行 ./gradlew clean 清理本地构建缓存
  2. 重新运行项目构建命令(如 react-native run-android)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 09:45:37