【安卓开发】【Android Studio】【Gradle】项目构建报错:Plugin version: ‘x.x.x‘ apply: false was not found

一、问题说明

在构建安卓项目时,Build不成功,报错:

Plugin [id: ‘com.android.application‘, version: ‘x.x.x‘, apply: false] was not found

定位出错代码:

build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.6.4' apply false
    id 'com.android.library' version '7.6.4' apply false
}

其中,插件版本7.6.4是笔者在gradle官网找到的:

在这里插入图片描述

笔者的JDK版本:

OpenJDK 12.0.2
在这里插入图片描述

二、解决方法

参考了以下网址:

1、Gradle版本一览

2、Stack Overflow

3、CSDN博客

将我的插件版本改成8.0.2即可:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
}

如图,可以正常下载所需的插件:

在这里插入图片描述

三、后续报错

Gradle JVM version incompatible.
This project is configured to use an older Gradle JVM that supports up to version 12 but the current AGP requires a Gradle JVM that supports version 17.

提示Gradle JVM版本和插件版本不匹配。

解决方法:

在设置中将JDK版本修改为较高版本(>= 17)即可。

在这里插入图片描述

四、相关报错

和版本相关的报错还有许多,这里一并总结,比如常遇到的 Android API 版本报错:

An issue was found when checking AAR metadata:

  1.  Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.2 is 33.  # 提示我的插件版本8.0.2匹配的最高API为33

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

定位到build.gradle文件:

android {
    namespace 'com.example.intent_test_2'
//    compileSdk 35
    compileSdk 33
    defaultConfig {
        applicationId "com.example.intent_test_2"
        minSdk 25
        targetSdk 33
        versionCode 1
        versionName "1.0"

将compileSdk和targetSdk修改为34即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不是AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值