Flutter JDK 版本在 Mac 上没有变化。为什么?我该如何解决?

问题描述 投票:0回答:0

你好我是mac的,我按照很多教程说的改了sdk版本。如果我跑

java --version
我得到这个:

openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment Homebrew (build 11.0.19+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.19+0, mixed mode)

问题是当我运行

flutter doctor --verbose
我在android studio上得到这个:

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

JDK 版本不同。当我尝试运行一个 flutter 项目时,我得到了这个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @52a71430

附加信息

  • 当我通过android中的android文件夹打开我的flutter项目时 studio我可以配置

    project settings
    和选择jdk版本

  • 仅当我在 android 的 android 文件夹中运行该应用程序时才有效 工作室。如果我从根目录运行它,它会抛出同样的错误。

  • /usr/libexec/java_home -V
    的命令输出是这样的:

Matching Java Virtual Machines (1):
    11.0.19 (arm64) "Homebrew" - "OpenJDK 11.0.19" /opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home
/opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home
  • 在我的 ~/.zshrc 中,我导出了
    export JAVA_HOME='/opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home'

有办法解决吗?

java android flutter java-11
© www.soinside.com 2019 - 2024. All rights reserved.