AndroidStudio报错:Failed to resolve: com.github.CymChad:BaseRecyclerViewAdapterHelper

项目场景:

最近接手了一个新的项目,在导入依赖的时候出现了报错,经过排查后发现是BaseRecyclerViewAdapterHelper这个包没有导入成功,下面是解决的方法,记录一下。


原因分析:

首先我们来看一下具体的错误信息:

> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18.
     Required by:
         project :app
      > Could not resolve com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18.
         > Could not get resource 'https://dl.bintray.com/umsdk/release/com/github/CymChad/BaseRecyclerViewAdapterHelper/2.9.18/BaseRecyclerViewAdapterHelper-2.9.18.pom'.
            > Could not GET 'https://dl.bintray.com/umsdk/release/com/github/CymChad/BaseRecyclerViewAdapterHelper/2.9.18/BaseRecyclerViewAdapterHelper-2.9.18.pom'. Received status code 502 from server: Bad Gateway

相信有的朋友已经看出来了,这是由于某种禁制导致我们无法下载到BaseRecyclerViewAdapterHelper/2.9.18/BaseRecyclerViewAdapterHelper-2.9.18.pom这个文件,直接跟这种法则级别的禁制硬刚显然不是明智的选择,那么我们有什么办法解决呢。

解决方案:

首先:先确认自己有没有翻墙成功,配置如图:

然后:

普遍做法:

其实出现这种问题的不在少数,网上相关的解决办法也都大同小异,基本都是把project下的gradle做如下修改。

allprojects {
    
    
    repositories {
    
    
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
        //修改前
        //maven { url "https://jitpack.io" }
        //修改后
       maven {
    
     url "https://www.jitpack.io" } 
    }
}

经过尝试,这种方法并不适用我的项目,问题依旧存在。

阿里云镜像仓库:

上述方法行不通后,我又翻阅了一些资料,在Gitee发现同样有后决定使用阿里云镜像仓库下载,方法网上也可以找到,也很简单,只需要做如下修改即可:

allprojects {
    
    
    repositories {
    
    
   		//阿里云仓库地址
   		maven {
    
     url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
        maven {
    
     url "https://www.jitpack.io" } 
    }
}

到这一步,相信一部分小伙伴已经可以正常拉取依赖,开始愉快的编程了,但有些朋友估计还是不能解决问题,我就是属于后者,那我们接下来怎么办呢,我这里提供一种解决的办法。

探秘阿里云镜像仓库:

通过阿里云镜像仓库地址我们可以看到如下界面:

首先我们查看一下仓库地址,很显然没有问题:

然后我们接着往下走:点击文件搜索,输入我们要找的包:BaseRecyclerViewAdapterHelper

跟前面的报错信息一对比,这不就是我们又爱又恨的pom文件吗,也在jcenter仓库下,只是版本不相同,等一下,版本不相同?,没错,在翻阅了搜索的结果后,我发现这个仓库中没有我导入的2.9.18版本。 

//我项目导入的依赖版本 dependencies { //... implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18' }

赶紧将版本号换到临近的2.9.34版本,再运行一下试试,解决了。

总结
1.在实际操作中,我们可以根据官方文档Gitee上BaseRecyclerViewAdapterHelper地址和阿里云镜像仓库中的版本(阿里云镜像仓库地址)对比,来择优选择最合适的版本使用。
2.举一反三,我们在遇到其他下载不下来的第三方依赖时,也可以用类似的方法,在阿里云镜像仓库搜索并下载替代版本使用。

转载:https://blog.csdn.net/BX_Jobs/article/details/126191098

猜你喜欢

转载自blog.csdn.net/gqg_guan/article/details/129582534
今日推荐