当我单击run时收到此消息:
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.Error message "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"在设置中更改Gradle JDK的答案是有效的。,但只适用于这一个项目,。当我创建一个新项目时,Android会自动再次使用默认1.8。
我有11个可用的,只是不自动使用它。我尝试过的事情:在这里将JAVA_HOME env更改为JDK 11的位置,但仍然得到相同的错误。
无效的缓存/restart一堆时间什么也不做
如何设置一次并将其应用于所有未来的新项目?

附加应用程序/build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.grid"
minSdk 22
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}顶层build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}发布于 2022-01-09 13:46:19
可能有点晚了,但我只是安装了所需的java,顺便说一下,安装了jdk 17。这是在从我的浏览器下载并安装它之后。然后您可以使用cmd上的"java - version“命令检查设备上的java版本,然后重新启动pc并打开android。然后在android studio中的终端上检查gradlew -version命令的jvm,如果更新了,就可以继续了。
发布于 2022-02-10 19:46:34
安装了多个Android Studio?
简短答覆:
只需删除另一个版本,它就会解决问题。
较长的答覆:
我安装了两个版本的Android:Android4.2和Android北极福克斯。两个Android都安装了不同的Gradle JDK版本。
这就是我在北极狐级设置中所看到的。(默认选择为1.8)

我的理论:
如果您注意到,Gradle JDK安装在应用程序/Android/Content/
我的假设是,Gradle Settings页面会提取所有已安装的Gradle JDK版本。在“设置”页面中没有设置默认版本的选项。因此,第一级版本变成了默认版本。
我不知道它是alphabetically排序的,还是基于下载时间戳的。
但我相信这是基于时间戳的。最老的安装版本在列表中排在首位。
这里有一个支持性的观察。当我删除AndroidStudio4.2和ctrl+z (撤销)时,列表顺序发生了变化。

免责声明:
我可能完全错了,因为我没有任何官方医生,链接支持这一说法。这只是一种理论。
我知道这不是一个理想的解决方案,因为删除旧的Android可能不是每个人的选择。
发布于 2021-12-06 17:52:59
你试过: app模块build.gradle文件。
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
}还尝试选择默认提供的

https://stackoverflow.com/questions/70228745
复制相似问题