gradle:org.gradle.api.internal.artifacts.ivyservice或Could not find com.android.support:appcompat-v7

使用as进行编译,一直报错,展示问题具体日志如下:

FAILURE: Build completed with 9 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.android.support:appcompat-v7:28.0.0-alpha3.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/support/appcompat-v7/28.0.0-alpha3/appcompat-v7-28.0.0-alpha3.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

首先根据这个日志考虑:

org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

一开始怀疑是gradle版本不对应导致的问题,所以去官网文档查了一下对应的gradle插件和版本的关系:

https://developer.android.com/studio/releases/gradle-plugin?hl=zh-cn

然后就根据表格中的映射关系进行配置,然后sync同步一下gradle配置,结果不行,编译跑起来一直报错;

然后根据这个日志考虑:

Could not find com.android.support:appcompat-v7:28.0.0-alpha3.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/support/appcompat-v7/28.0.0-alpha3/appcompat-v7-28.0.0-alpha3.pom

是否是因为没有下载到对应的依赖包导致呢,然后就去定位到根目录的build.gradle是否没有配置对应的仓库路径,当中查找了stackflow也指向了同一个问题(地址:gradle - Failed to resolve: com.android.support:appcompat-v7:28.0 - Stack Overflow

结果发现根目录下的build.gradle的仓库只配置了jcenter()而没有配置google的仓库路径,

然后在对应的路径下都配置google仓库的地址(问题解决):

allprojects {
    repositories {
    ...
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        } //配置google谷歌仓库
    ...
    }
}

如果还不行,顶部的buildscript也需要配置:

buildscript {
    repositories {
        google() //配置google谷歌仓库
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
    }
}

注:jcenter()仓库是已经放弃运营了,所以看到指向jcenter()的仓库无法下载对应依赖包,就可以考虑其他仓库是否有对应的包。国内环境就去找找对应大公司的仓库镜像吧

到此,问题解决,如果各位同学在开发中遇到这些让人头痛又耗时的问题,及时记录下来,避免下次重复掉坑而想不起来如何解决的,也是一个好的解决问题的思路总结。

遇事不要慌,google在手,csdn你有。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值