Libgdx doesn't work on Fedora 31 - Could not initialize class org.lwjgl.Sys

Viewed 1227

I downloaded libgdx from official website (so I suppose it's up to date), then opened it by gradle in Intellij. I didn't change any code and compiled the default code. This is my build config:

enter image description here

Application doesn't work and i got this message:

Exception in thread "LWJGL Application" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.Sys
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:592)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)

I'm using Fedora 31 with GNOME 3.34.5. Do you have any idea how to fix it?

EDIT: I've tried the other way: cloned the code from libgdx's github and followed the instructions from their wiki:

Native binaries must be brought down in order to run. These binaries are built on the snapshot build server, so you need to run a task to bring them down. Even if you plan on building natives later yourself, its recommended to bring these down so you can test your development environment is setup before moving to the next step. From the LibGDX root directory Through Gradle:

./gradlew fetchNatives


After running this I received:

    FAILURE: Build failed with an exception.

What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
3 Answers

I have no reputation, so I can't edit or comment, but with some minor tweeks, I was able to get alekseymishanin's solution to work.

Background Info: Ubuntu 20.04, when I switch from JDK 8 to 16, the example libGDX fails to build.

Fix

  1. Upgrade the gradle wrapper to 7.0. You probably already did this, as without this fix, you get a compile time error: ./gradlew wrapper --gradle-version 7.0
  2. Switch to lwgl3 in the build.gradle by replacing api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" with api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
  3. In DesktopLauncher.java, update the imports accordingly, and replace all instances of Lwjgl with Lwjgl3. For example, new LwjglApplicationConfiguration() becomes new Lwjgl3ApplicationConfiguration()

I got the very same issues while trying to run a libgdx project with java 14 and/or gradle 6.6.1.

Exception in thread "LWJGL Application" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.Sys

came up when I tried to run the project with gradle 6.6.1 and java 14, and the other error:

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

came up when I was trying it with an older version of gradle but still using java 14.

Maybe downgrading to java 11 could help? It solves my issue...

If you are using java above version 8, then try changing this

dependencies {
    api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
}

to this

dependencies {
    api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"     
}
Related