如何修复 Android Studio Flamingo 在 MacOS 上要求使用 Java 11 运行的问题?

huangapple go评论74阅读模式
英文:

How to fix Android Studio Flamingo asking to use Java 11 to run on MacOS?

问题

我安装了最新版的Android Studio Flamingo并尝试运行一个Flutter代码项目,但遇到了以下错误代码:

无法应用插件 'com.android.internal.application'。
   > Android Gradle插件需要Java 11才能运行。您当前正在使用Java 1.8。

我尝试了在stackoverflow上发布的解决方案,但我的Android Studio没有Gradle JDK选择选项。请问有谁可以帮忙吗?

英文:

I did a fresh install of the Android Studio Flamingo and tried to run a flutter code project but encounter this error code.

Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

I tried the solutions posted on stackoverflow but my Android Studio does not have the Gradle JDK selection option

Can anyone help?

答案1

得分: 2

以下是翻译好的部分:

我遇到了一个略有不同的问题,但我认为解决方法可能是相同的。

我遇到的错误是“class file major version 61”,在阅读了这篇文章之后,我明白我需要将我的项目编译为Java 11,我认为这也会解决你的问题。

修复步骤:

  1. 下载Java 11 - brew install openjdk@11
  2. 将它创建符号链接到你的JVM文件夹 - 在上述命令的输出中,找到“For the system Java wrappers to find this JDK, symlink it with <command>” - 运行这个命令
  3. android/gradle.properties 中添加一行 org.gradle.java.home=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home

好处在于你并没有改变你的Java主目录或其他项目所需的Java 1.8版本,你只是告诉这个项目要使用Java 11进行编译。

英文:

I faced a slightly different problem, but I think the resolution could be the same.

The error I had was "class file major version 61", and after reading this, I understood I needed my project to compile with Java 11, and I think that will resolve your issue as well.

Steps to fix:

  1. Download java11 - brew install openjdk@11
  2. Symlink it to your JVM folder - In the output of the above command, find "For the system Java wrappers to find this JDK, symlink it with <command>" - run this command
  3. In android/gradle.properties, add line org.gradle.java.home=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home

The good thing here is that you aren't changing your java home value or anything so if you need java 1.8 for other projects that's fine, you're just telling this project to compile with 11

huangapple
  • 本文由 发表于 2023年5月21日 15:06:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298692.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定