最近升级了一下Android Studio ,然后在开发Flutter项目时就出现了这样的问题!!!
* 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`.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
也就是说当前 工程需要 使用 java 11 来编译,但我当前的开发环境是 java8,其实简单的方法就是把本地的开发环境 java8升级到java11,但是我的其他工程项目可能就会出现问题,所以还不能使用这种方法。
最适合的解决方法
下载 java11 到本机,然后在工程的 gradle.properties 中添加一个参数即可,比如我这里应该是
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
我本机是安装了三个版本