Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

问题描述:

打包release版本时,提示FAILURE: Build failed with an exception.并报如下错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/mi/AndroidStudioProjects/gitrepo/Mids911/app/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> 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`.

解决方案

降低Gradle版本

在项目的build.gradle下,降低gradle版本,从7.0降低到4.2.1,解决了问题。

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.5.0'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    compileSdkVersion = 30
    buildToolsVersion = "30.0.3"
    minSdkVersion = 21
    targetSdkVersion = 30
}


升级jdk版本

File->Settings->Build~~->Build Tools->Gradle,修改Gradle JDK的版本号为11。
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
最后,再重新编译即可。

上一篇:codeforces 1156E Special Segments of Permutation


下一篇:AndroidStudio修改项目包名