前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【错误记录】Android 编译报错 ( Could not resolve xxx | 手动下载依赖库并进行本地配置 Gradle 依赖的解决方案 | 构建 Maven 依赖下载路径 )

【错误记录】Android 编译报错 ( Could not resolve xxx | 手动下载依赖库并进行本地配置 Gradle 依赖的解决方案 | 构建 Maven 依赖下载路径 )

作者头像
韩曙亮
发布2024-04-20 08:45:33
1520
发布2024-04-20 08:45:33
举报

一、报错信息

编译 Android Studio 项目时 , 报如下错误 , 下载依赖库失败 ;

报错信息 :

代码语言:javascript
复制
Execution failed for task ':ijkplayer-exo:generateDebugRFile'.
> Could not resolve all files for configuration ':ijkplayer-exo:debugCompileClasspath'.
   > Could not resolve com.google.android.exoplayer:exoplayer:r1.5.11.
     Required by:
         project :ijkplayer-exo
      > Could not resolve com.google.android.exoplayer:exoplayer:r1.5.11.
         > Could not get resource 'https://raw.githubusercontent.com/Pgyer/analytics/master/com/google/android/exoplayer/exoplayer/r1.5.11/exoplayer-r1.5.11.pom'.
            > Could not HEAD 'https://raw.githubusercontent.com/Pgyer/analytics/master/com/google/android/exoplayer/exoplayer/r1.5.11/exoplayer-r1.5.11.pom'.
               > raw.githubusercontent.com

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

二、解决方案

1、确定 Maven 仓库地址

下面是 当前 Android 项目的 Gradle 配置中的 Maven 仓库 ;

代码语言:javascript
复制
allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        // ijkplayer 仓库
        maven { url "https://repo.spring.io/plugins-release/" }
        maven { url "https://repository.mulesoft.org/nexus/content/repositories/public/" }
        maven { url "https://dl.bintray.com/bilibili/maven/" }
    }
}

其中使用 maven { url "https://repo.spring.io/plugins-release/" } 配置的 Maven 仓库就是对应的地址 ;

使用 google() 函数配置的 Maven 仓库地址 是 https://maven.google.com/ , 可以通过 https://maven.google.com/web/index.html 地址搜索对应的 依赖库 ;

使用 mavenCentral() 函数配置的 Maven 仓库地址是 https://repo1.maven.org/ ;

使用 jcenter() 函数配置的 Maven 仓库地址是 http://jcenter.bintray.com , 目前已经无法访问 , 其依赖库都迁移到了 Maven 中央仓库 ;

2、构建 Maven 依赖下载路径

以 下载 org.springframework.boot:spring-boot-starter-web:2.5.0 为例 ,

  • 组织ID 是 org.springframework.boot , 其对应的路径是 org/springframework/boot/ ;
  • 构件ID 是 spring-boot-starter-web ;
  • 版本号 是 2.5.0 ;

下载路径公式是 : 仓库地址/组织ID/构件ID/版本号/构件ID-版本号.jar ;

仓库地址是 https://repo1.maven.org/maven2/ 地址 ;

按照上面的公式拼接起来就是 https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-web/2.5.0/spring-boot-starter-web-2.5.0.jar ;

将拼接的 https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-web/2.5.0/spring-boot-starter-web-2.5.0.jar 地址拷贝到浏览器中 , 就可以下载该 依赖库 ;

下载完成后的文件如下 :

建议使用 wget 或者 curl 命令行工具下载 ;

3、检查依赖库是否存在

通过上述 Maven 仓库依赖库地址拼接 , 就可以知道 该 依赖库是否在 Maven 仓库中存在 , 如果存在就可以下载 , 如果不存在 , 则下载失败 ;

到 Maven 仓库中 对应的地址 , 查找对应的依赖库 ;

如 : Maven 中央仓库 , 使用 mavenCentral() 配置 ;

代码语言:javascript
复制
allprojects {
    repositories {
        mavenCentral()
    }
}

对应的地址是 https://repo1.maven.org/maven2/ , 进入该页面后 , 显示的内容如下 :

按照路径查找 com.google.android.exoplayer:exoplayer:r1.5.11 依赖库 ;

找到 https://repo1.maven.org/maven2/com/google/android/ 层级 , 就没有对应的依赖库了 , 说明在 Maven 中央仓库 https://repo1.maven.org/maven2/ 中没有 com.google.android.exoplayer:exoplayer 依赖库 ;

4、在 Gradle 中配置本地依赖

下载到本地后 , 将 下载的 依赖库拷贝到本地路径中 , 然后将相对路径配置到 dependencies / implementation 依赖中 ;

代码语言:javascript
复制
dependencies {  
    implementation files('path/to/your/downloaded/dependency.jar')  
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-04-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、报错信息
  • 二、解决方案
    • 1、确定 Maven 仓库地址
      • 2、构建 Maven 依赖下载路径
        • 3、检查依赖库是否存在
          • 4、在 Gradle 中配置本地依赖
          相关产品与服务
          命令行工具
          腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档