英文:
General error during semantic analysis: Unsupported class file major version 57
问题
我正在尝试为桌面游戏设置libgdx,当我尝试生成项目时,出现了这个错误,构建失败了。我有最新版本的Java(13.0.2)和Gradle(6.6),都设置为环境变量在路径中。有人可以帮助我吗?
这个错误看起来像这样:
无法编译设置文件'C:\Users\noemi\Desktop\Test\settings.gradle'。
> 启动失败:
语义分析期间发生常规错误:不支持的类文件主版本 57
java.lang.IllegalArgumentException:不支持的类文件主版本 57
英文:
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?
The error looks like this:
Could not compile settings file 'C:\Users\noemi\Desktop\Test\settings.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 57
java.lang.IllegalArgumentException: Unsupported class file major version 57
答案1
得分: 29
这不是一个LibGDX的问题。Gradle 5与Java 13不兼容。你需要将项目中包装的Gradle版本更新到Gradle 6或更新版本,或者使用较低版本的JRE。
要更新包装的Gradle,前往项目中的gradle/wrapper/gradle-wrapper-properties
,然后更新版本号。我使用的是6.1.1版本。
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
如果你有一个较旧的LibGDX项目,可能需要修改android
模块中的build.gradle
文件以与Gradle 6兼容。你可以复制粘贴,用这里的内容替换copyAndroidNatives
任务。
英文:
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.
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
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.
答案2
得分: 25
> 启动失败:
语义分析期间出现常规错误:不支持的类文件主版本 61
如何修复此 React Native 问题
JAVA JDK 17
转到您的 React Native 项目的 android/ 目录
创建一个名为 local.properties 的文件,文件内容如下:
> sdk.dir=C:\Android\sdk
前往
android\gradle\wrapper\gradle-wrapper.properties
更改
> distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
为
> distributionUrl=https://services.gradle.org/distributions/gradle-7.3-all.zip
前往
> android\gradle.properties
添加以下行:
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
英文:
> startup failed:
General error during semantic analysis: Unsupported class file major version 61
how to fix this react native issues
JAVA JDK 17
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
> sdk.dir=C:\Android\sdk
GOTO
android\gradle\wrapper\gradle-wrapper.properties
CHANGE
> distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
TO
> distributionUrl=https://services.gradle.org/distributions/gradle-7.3-all.zip
GOTO
> android\gradle.properties
add this line
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
答案3
得分: 12
这个问题出现在我运行我两年前编写的旧的Flutter
项目时。我认为对于Android项目,解决方法也是一样的。我在使用MacOS
和Android Studio Bumblebee
。
首先,需要进入android
文件夹并检查gradle版本:
cd android
./gradlew --version
它显示Gradle版本为6.7.1
,你需要关注JVM行,而我的JDK版本是15.0.2。这对于这个项目来说太新了。所以你必须要么从OpenJDK版本降级到旧版本,要么在gradle/wrapper/gradle-wrapper.properties
中将Gradle版本升级到新版本。
如果你降级JDK版本,你可以从这里下载。在我的情况下,我将JDK版本从Java SE 15降级到了Java SE 11。
之后,我打开了Flutter项目的Android部分:
前往Preferences->Build, Execution, Deployment -> Build Tools -> Gradle
,选择JDK版本11。
然后,前往Build -> Clean Project -> Rebuild Project。
在Terminal
中运行java --version
,如果仍然显示JDK版本15,则必须在之前设置JAVA_HOME。
你只需要将以下内容添加到你的.bash_profile
或者.zshrc
文件中:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
保存并进入android
文件夹,然后再次运行:
./gradlew --version
它会显示JDK版本11的正确版本。
最后,运行flutter run
。
英文:
This problem occurred when I run my old Flutter
project that I coded 2 years ago. I think with Android project will also fix in the same way. I'm use MacOS
and Android Studio Bumblebee
.
First, need to move to the android
folder and check gradle version:
cd android
./gradlew --version
It show Gradle version 6.7.1
and you need attention to the JVM line, and my JDK version is 15.0.2. It is too new for this project. So you must to downgrading
from open jdk version to old version or upgrade
Gradle version in gradle/wrapper/gradle-wrapper.properties
to new version.
If you downgrade JDK version, you can download from this. In my case, I downgraded from Java SE 15 to Java SE 11.
After I open Android of Flutter project
Go to Preferences->Build, Execution, Deployment → Build Tools → Gradle →
and choose JDK version 11.
Go to Build -> Clean Project -> Rebuild Project.
Go to Terminal
run java --version
, if it still show JE version 15 then You must set JAVA_HOME before.
You only need to add the following to your .bash_profile
or .zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
Save and go to android
folder and run again
./gradlew --version
It will show JDK version 11 correct.
Finally, run flutter run
.
答案4
得分: 3
我已经降级了Gradle文件,所以出现了这个错误,所以最终我必须更改Gradle包装文件从
distributionUrl=https://services.gradle.org/distributions/gradle-7.2-all.zip
到
distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-all.zip
英文:
I have downgraded gradle file thats why this error happens so finally I have to change Gradle wrapper file From
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
答案5
得分: 2
如果您在使用Eclipse,前往
Eclipse > Preferences > Gradle
将“Java home”更新为指向Java的安装路径。
英文:
If you're using eclipse, go to
Eclipse > Preferences > Gradle
Update Java home
to point to Java home location
答案6
得分: 0
检查Gradle版本和捆绑版本,请使用以下链接:
链接 https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
如果您想升级android/gradle/build.gradle,请更改依赖项的类路径为 'com.android.tools.build:gradle:[最新版本]'。
英文:
Check gradle version and bundle version using the following link
Link https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
If you want to upgrade android/gradle/build.gradle change dependencies classpath 'com.android.tools.build:gradle:[latest version]'
答案7
得分: 0
Java(13.0.2)和Gradle(6.6)不兼容。
## 修复方法
你可以选择以下方式之一:
- 将你的JDK版本更改为14。修改环境变量`JAVA_HOME`的路径。
- 或者保持你的JDK版本为13.x,将Gradle版本更改为6.0。在你的项目`gradle/wrapper/gradle-wrapper.properties`中,将以下行更改为`distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip`。[可用的Gradle发行版][1]
如何知道兼容的版本?
## Java兼容性表格
查阅:https://docs.gradle.org/current/userguide/compatibility.html
|Java版本|首个支持它的Gradle版本|
|------------|-----------|
|8| 2.0|
|9|4.3|
|10|4.7|
|11|5.0|
|12|5.4|
|13|6.0|
|14|6.3|
|15|6.7|
|16|7.0|
|17|7.3|
|18|7.5|
|19|7.6|
|20|8.1 ⚠|
[1]: https://services.gradle.org/distributions/
英文:
Java(13.0.2) and Gradle(6.6) are not compatible.
Fix
You can either :
- change your JDK version to 14. Path to environment variable
JAVA_HOME
- or keep your JDK to 13.x and change your Gradle version to 6.0 . In your project
gradle/wrapper/gradle-wrapper.properties
, change the line todistributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
. Available Gradle distributions
How to know the compatible versions ?
Table Java Compatibility
Check this https://docs.gradle.org/current/userguide/compatibility.html
Java version | First Gradle version to support it |
---|---|
8 | 2.0 |
9 | 4.3 |
10 | 4.7 |
11 | 5.0 |
12 | 5.4 |
13 | 6.0 |
14 | 6.3 |
15 | 6.7 |
16 | 7.0 |
17 | 7.3 |
18 | 7.5 |
19 | 7.6 |
20 | 8.1 ⚠ |
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论