当前位置: 首页 > 知识库问答 >
问题:

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

曾嘉荣
2023-03-14

单击“运行”时收到此消息:

> 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`.

错误消息“AndroidGradle插件需要Java11才能运行。您目前正在使用Java1.8”来更改设置工作中的格拉德尔JDK。但只适用于那个项目。当我创建一个新项目时,Android Studio会自动再次使用默认的1.8。

我有11个可用的,因为它不会自动使用。我尝试的事情:在这里将JAVA_HOMEenv更改为JDK 11的位置,但仍然得到相同的错误。

无效缓存/重新启动大量时间无效

附加应用程序/构建。格拉德尔

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
}

共有1个答案

麹高义
2023-03-14

您是否尝试过:应用程序模块构建。格雷德尔档案。

android {
    // ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
}
 类似资料:
  • 问题内容: 尝试更改列的数据类型并设置新的默认值时遇到以下错误: 错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第1行的’VARCHAR(255)NOT NULL SET DEFAULT’{}’‘附近使用正确的语法 问题答案: 同样的第二种可能性(感谢juergen_d):

  • 在尝试更改列的数据类型并设置新的默认值时,我遇到以下错误: 错误1064(42000):您的SQL语法中有错误;查看与您的MySQL server版本相对应的手册,以了解第1行“varchar(255)NOT NULL SET DEFAULT”{}“附近使用的正确语法

  • 问题内容: 我从SVN中签出了一个项目,但未指定项目类型,因此它作为“默认”项目签出。快速将其转换为“ Java”项目的最简单方法是什么? 我正在使用Eclipse版本3.3.2。 问题答案: **打开.project文件,然后添加Java性质和构建器。 在.classpath中,引用Java库: **

  • 问题内容: 我想将MySQL服务器的默认端口号更改为3306。我想将其更改为3360。 我努力了: 但是事情对我不起作用。请提供查询以更改端口而不进行任何配置。我正在使用Windows 8 64位。 问题答案: 您需要编辑文件,并确保已按照以下行设置了端口: 然后重新启动MySQL服务,您应该一切顺利。没有查询,您可以运行以进行更改,因为它不是动态变量(有关MySQL文档,其中显示了所有系统变量的

  • 我在JScrollpane中显示了一个JTable。JTable在其网格中只显示几行信息。网格下面到JPanel底部的空间,包含JScrollpane(它又包含JTable),为纯灰。我想把那个颜色改成白色。我尝试将JTable的背景色设置为白色,[使用setBackground(color,white)]方法,但没有成功。 谁能告诉我用哪种方法把灰色变成白色?

  • 问题内容: 我使用IntelliJ IDEA作为开发环境,并使用Maven进行依赖项管理。我经常在IDEA之外构建我的项目结构(目录,poms等),然后使用将该项目导入。这很好用,除了在poms中我指定maven-compiler-plugin应该使用JDK 1.6,并且在导入时,IDEA通知我和,然后提示重新加载项目。这很烦人,因为我总是使用相同的JDK版本。 如何更改IntelliJ IDEA