语义分析期间的一般错误:不支持的类文件主要版本 57

2022-01-12 00:00:00 desktop-application gradle java libgdx

我正在尝试为桌面游戏设置 libgdx,当我尝试生成项目时出现此错误并且构建失败.我有最新版本的 Java(13.0.2) 和 Gradle(6.6),它们都设置为路径中的环境变量.有人可以帮帮我吗?

I'm trying to setup libgdx for a desktop game and when I try to generate the project I have this error and the build fails. I've the latest versions of Java(13.0.2) and Gradle(6.6), both set as environment variables in the path. Can somebody help me?

错误如下所示:

Could not compile settings file 'C:Users
oemiDesktopTestsettings.gradle'.
> startup failed:
  General error during semantic analysis: Unsupported class file major version 57
  
  java.lang.IllegalArgumentException: Unsupported class file major version 57 

推荐答案

这不是 LibGDX 问题.Gradle 5 与 Java 13 不兼容.您需要将 Gradle(项目中的包装版本)更新到 Gradle 6 或更高版本,或者需要使用较低版本的 JRE.

This is not a LibGDX issue. Gradle 5 is incompatible with Java 13. You either need to update Gradle (the wrapped version in your project) to Gradle 6 or later, or you need to use a lower version of the JRE.

要更新打包的 gradle,请转到项目中的 gradle/wrapper/gradle-wrapper-properties 并更新版本号.我正在使用 6.1.1.

To update the wrapped gradle, go to gradle/wrapper/gradle-wrapper-properties in your project and update the version number. I'm using 6.1.1.

distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

如果您有较旧的 LibGDX 项目,您可能需要修改 android 模块中的 build.gradle 文件以与 Gradle 6 兼容.您可以复制-粘贴以将 copyAndroidNatives 任务替换为 这里的那个.

If you have an older LibGDX project, you might have to modify the build.gradle file in the android module to be compatible with Gradle 6. You can copy-paste to replace the copyAndroidNatives task with the one here.

相关文章