[英]how can I change java version(android studio)
$ java -version
java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)
However when I run Flutter:但是,当我运行 Flutter 时:
* What went wrong:
A problem occurred evaluating project ':app'.
> 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
BUILD FAILED in 1s
┌─ Flutter Fix ─────────────────────────────────────────────────────────────────┐
│ [!] You need Java 11 or higher to build your app with this version of Gradle. │
│ │
│ To get Java 11, update to the latest version of Android Studio on │
│ https://developer.android.com/studio/install. │
│ │
│ To check the Java version used by Flutter, run `flutter doctor -v`. │
└───────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1
I can change gradle.properties like: org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
.我可以更改 gradle.properties,例如:
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
。 It worked, just this project, ever time new project
need change again.它起作用了,只是这个项目,每次
new project
需要再次更改。 How can I fix it.我该如何解决。
env:环境:
try:尝试:
cant find Gradle JVM
enter image description here找不到
Gradle JVM
在此处输入图像描述
Are you saying every time you create a new project you get this error?您是说每次创建新项目时都会出现此错误吗? Or every time you try to run the project?
或者每次您尝试运行项目时? Either way, it might be an IDE setting that is fixed in using JAVA 8 but your Gradle is configured for JAVA 11, thus causing the problem.
无论哪种方式,它都可能是在使用 JAVA 8 时修复的 IDE 设置,但您的 Gradle 配置为 JAVA 11,从而导致问题。 Your stack trace already tells you where to look at:
您的堆栈跟踪已经告诉您在哪里查看:
org.gradle.java.home
in gradle.properties
.org.gradle.java.home
中的gradle.properties
。 So make sure all of these are using the same JAVA version.因此,请确保所有这些都使用相同的 JAVA 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.