一、问题说明
在构建安卓项目时,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
二、解决方法
参考了以下网址:
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即可。