Java教程

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

本文主要是介绍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.的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!