【问题标题】:Issue with Java on Flutter for MacFlutter for Mac 上的 Java 问题
【发布时间】:2021-06-27 09:18:32
【问题描述】:

错误信息:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x71871a5e) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x71871a5e

* 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 42s
Exception: Gradle task assembleDebug failed with exit code 1

我刚刚安装了JDK,当我尝试在Android端运行时会出现这种情况。

有人可以向我解释这是什么以及如何解决它吗?

一切都是最新版本。

【问题讨论】:

    标签: java android macos flutter android-studio


    【解决方案1】:

    对我来说,原来是 Gradle 的 java 版本兼容性问题。我从 Java SE 16 降级到 Java SE 11 并解决了这个问题。

    【讨论】:

    • 谢谢!有什么想法可能导致这种情况吗?
    • 你能解释一下你是如何在 Android Studio 上降级 Java 的吗?
    【解决方案2】:

    这是因为你的$JAVA_HOME 没有设置

    .bash_profile中导出JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home"

    【讨论】:

    • 终端重启后,我得到这个错误:ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home Please set the JAVA_HOME variable in your environment to match the location of your Java installation.@Usama Altaf
    • JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk 在这条路径上尝试,但ofcource用你自己的路径替换它
    • 不能解决我的问题 :( 我已经设置了JAVA_HOMEexport JAVA_HOME=$(/usr/libexec/java_home -v 11) 不起作用,JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home 也是如此。
    • 如果我通过终端运行flutter run,一切正常。但是如果我通过 VS Code 运行,我会收到此错误。我已经尝试设置“java.home”,但这并没有什么不同。 Java 扩展包也指向正确的路径。
    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多