开发者社区> 韩曙亮> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )

简介: 【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )
+关注继续查看

文章目录

一、 报错信息

二、 解决方案





一、 报错信息


导入了一个 Eclipse 项目 , 编译后报如下错误 :


FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'MidiSheetMusic_02'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:4.2.1.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.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.
     Required by:
         project :
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'MidiSheetMusic_02'.
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.android.tools.build:gradle:4.2.1.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.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.
Required by:
    project :
* Get more help at https://help.gradle.org
BUILD FAILED in 1s


image.png





二、 解决方案


检查了下根目录下的 build.gradle 配置 , 发现只配置了 jcenter 仓库 ;


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}


添加 google 仓库 和 mavenCentral 仓库 , 问题解决 ;


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
【错误记录】Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | 仅做参考 | 没有解决实际问题 )
【错误记录】Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | 仅做参考 | 没有解决实际问题 )
66 0
【错误记录】Android Studio 编译报错 ( A problem occurred starting process ‘command ‘ninja.exe‘ ‘ )
【错误记录】Android Studio 编译报错 ( A problem occurred starting process ‘command ‘ninja.exe‘ ‘ )
148 0
【错误记录】Android Studio 编译报错 ( cannot open this project, please retry with version 4.2 or newer. )
【错误记录】Android Studio 编译报错 ( cannot open this project, please retry with version 4.2 or newer. )
143 0
【错误记录】Android Studio 编译报错 ( Cannot use connection to Gradle distribution . as it has been stopped. )
【错误记录】Android Studio 编译报错 ( Cannot use connection to Gradle distribution . as it has been stopped. )
334 0
【错误记录】Android Studio 编译报错 ( SDK location not found )
【错误记录】Android Studio 编译报错 ( SDK location not found )
287 0
【错误记录】Android Studio 编译报错 ( Invalid main APK outputs : EarlySyncBuildOutput )(一)
【错误记录】Android Studio 编译报错 ( Invalid main APK outputs : EarlySyncBuildOutput )(一)
168 0
【错误记录】Android Studio 编译报错 ( AppCompat does not support the current theme features )
【错误记录】Android Studio 编译报错 ( AppCompat does not support the current theme features )
74 0
【错误记录】Android Studio 编译报错 ( Invalid Gradle JDK configuration found )
【错误记录】Android Studio 编译报错 ( Invalid Gradle JDK configuration found )
127 0
【错误记录】Android Studio 编译报错 ( Gradle 下载错误导致 Failed to open zip file 报错 )
【错误记录】Android Studio 编译报错 ( Gradle 下载错误导致 Failed to open zip file 报错 )
35 0
+关注
韩曙亮
专注 Android 领域
2601
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载