gpt4 book ai didi

android - 如何将 Android Studio 默认 gradle JDK 更改为 11

转载 作者:行者123 更新时间:2023-12-04 23:40:48 35 4
gpt4 key购买 nike

单击运行时收到此消息:

> 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 Studio 会再次自动使用默认 1.8。
我有 11 个可用,AS 只是不会自动使用它。
我尝试过的事情:在这里将 JAVA_HOME 环境更改为 JDK 11 的位置,但仍然出现相同的错误。
无效缓存/restart 一堆时间什么都没做
如何设置一次并将其应用于所有 future 的新项目?
enter image description here
附加 app/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
}

最佳答案

可能看起来晚了,但我通过安装所需的 java jdk 来修复我的问题,顺便安装了 jdk 17。那是从我的浏览器下载并安装它之后。
然后您可以使用以下方法检查您设备上的 Java 版本; cmd上的“java --version”命令,然后你可以重新启动你的电脑并打开android studio。然后在 android studio 的终端上检查 gradlew --version 命令的 jvm,如果它已更新,你就可以开始了

关于android - 如何将 Android Studio 默认 gradle JDK 更改为 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70228745/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com