解决“Gradle project sync failed”,“Could not find com.android.tools.build:gradle:4.2.1.“

项目场景:

导入Android项目时出现:Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly.,以及报Could not find com.android.tools.build:gradle:4.2.1.
sync failed
ERROR

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 :
Add google Maven repository and sync project
Open File


问题解决

针对仅出现==Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly.==这个问题的,推荐看这篇博客【Android Studio】成功解决 “gradle project sync failed”

如果两个问题均出现,先解决error
更改build.gradle文件内容
1、更改前
build.gradle更改前
2、更改后(更改形式不唯一)
build.gradle更改后
注意:Android Studio版本、Gradle插件版本、所需Gradle版本之间要对应要求Android Gradle 插件版本说明
build.gradle文件中是Gradle插件版本,而gradle-wrapper.properties文件中是所需Gradle版本
在这里插入图片描述


Gradle插件版本4.2.0+ ,所需Gradle版本6.7.1+
在这里插入图片描述

我这里使用的Gradle插件版本为4.2.1,所需Gradle版本为6.8
gradle-wrapper.properties文件内容:
在这里插入图片描述
编译出现警告Warning: Mapping new ns to old ns,解决方法建议参考
Android编译出现Warning: Mapping new ns to old ns的解决方案

注:此文仅描述本人所遇问题及解决方案。有类似问题的朋友,此文提供的解决方案仅供参考。


参考:
Android Studio报错:Error:Could not find com.android.tools.build:gradle:4.1 记一次不长记性的坑
Android Studio 配置Gradle总结
【Android Studio】成功解决 “gradle project sync failed”
Android编译出现Warning: Mapping new ns to old ns的解决方案


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值