有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓 Flatter找不到捆绑的Java版本

我无法从VS代码运行颤振应用程序

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 @0x3d67da21) 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 @0x3d67da21

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

我说的话:

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale
    en-RS)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio
    ✗ **Unable to find bundled Java version.**
[✓] Connected device (2 available)

共 (2) 个答案

  1. # 1 楼答案

    我通过创建一个符号链接解决了这个问题:

    cd /Applications/Android\ Studio.app/Contents/jre;
    ln -s ../jre jdk;
    ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
    

    这不是最优雅的解决方案,但很有效。问题是,系统找到了两个java版本,要么android许可证不被接受,要么捆绑版本找不到。因此,我删除了链接并添加了另一个链接。这终于成功了

    资料来源:https://github.com/flutter/flutter/issues/27136#issuecomment-888915746

  2. # 2 楼答案

    我认为您应该在Android Studio中指定Java SDK的路径,您可以通过以下操作进行设置:

    Generally speaking, it is set in the "Project Structure" dialog.

    Go to File > Project Structure > SDK Location. The third field is "JDK Location" where you can set it. This will set it for the current project.

    How to set Java SDK path in AndroidStudio?