gradle升级8.0踩坑记录——构建环境篇Could not resolve com.android.tools.build:gradle-api:8.0.0/7.x.x.

Could not resolve com.android.tools.build:gradle-api:8.0.0.

在这里插入图片描述
一般来说,这种报错有两个排查思路。
第一个网络原因,解决方式是换源
第二个,检查当前项目gradle使用的jdk版本,及构建脚本里的jdk版本配置

具体方案

先确保JDK设置的对,android gradle plugin 7.+要求jdk11去编译; agp8则要求jdk17.
设置路径 file - project structure - gradle settings - Gradle JDK 选择17或者11,没有对应的jdk则选择下载
在这里插入图片描述

再确保网路环境:顶级构建脚本里添加

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.4.0-alpha08")
      
    }
}
allprojects {
        repositories {
        google()
        jcenter()
    }
}

点击同步,还不行的话添加阿里云的仓库url。 顶级脚本配置变成如下:

buildscript {
    repositories {
    maven {
        url 'https://maven.aliyun.com/repository/google' }
// 如果有其他仓库的依赖需要 可以添加阿里云仓库如下 注意 gradle8需要为http的url显式声明允许使用不安全协议 allowInsecureProtocol = true 否则同步时报错
	maven {
        allowInsecureProtocol = true
        url 'http://mvnrepo.alibaba-inc.com/mvn/repository' }
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.4.0-alpha08")
      
    }
}
allprojects {
        repositories {
        google()
        jcenter()
    }
}

到这一步,同步一下,还不行则检查
模块的build.gradle中是否设置了适配java8的语言特性
如果出现了下列配置

sourceCompatibility = 1.8

将其删除 再次同步。
到这里,up的工程就正常了。希望能够帮到你。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I don't have access to the specific details of your project or environment. However, here are some general steps you can take to resolve this error: 1. Check your internet connection: Make sure you have a stable internet connection and try re-syncing your project with Gradle by clicking on the "Sync Now" button in the toolbar. 2. Check your Gradle version: Make sure you have the latest version of Gradle installed. You can check the version of Gradle in your project by opening the Gradle panel (located on the right side of the Android Studio window) and looking for the version number. 3. Update your Gradle settings: If you're using an older version of Gradle, you may need to update your Gradle settings to support the latest version of the Android Gradle plugin. You can do this by updating the "build.gradle" file in your project. 4. Check the repository configuration: Make sure that the repository configuration in your "build.gradle" file is correct and up-to-date. You can check the latest version of the Android Gradle plugin and make sure it's included in your repository configuration. 5. Use a stable version: If you're still having trouble with the alpha version, try using a stable version of the Gradle plugin instead. You can do this by updating your "build.gradle" file and specifying a stable version of the Gradle plugin. If none of these steps work, you may need to seek further assistance from the Android community or consult the official documentation.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值