libgdx: Can't run on Desktop: cannot find class com.badlogic.gdx.ApplicationListener
Issue details
There appears to be a bug on IntelliJ Idea which prevents the app from launching on Desktop from both IntelliJ and Android Studio on a Mac (still to confirm if it affects Windows as well). A Reddit post was created on /r/libgdx as well as an issue created on Jetbrains issue tracker (see https://www.reddit.com/r/libgdx/comments/612c7d/can_run_on_android_cannot_run_on_desktop/ for details).
Even if it’s no a libGDX bug I believe it is helpful to keep track on the progess of this as many users will see this crash when trying to launch on desktop using their IDE, feel free to close it otherwise.
Reproduction steps/code
Try to launch on Desktop a libGDX project using Intelli J version 2017.2.1 or Android Studio 2.3.3 on a Mac.
Version of LibGDX and/or relevant dependencies
1.9.6
Stacktrace
java.lang.ClassNotFoundException: cannot find class com.badlogic.gdx.ApplicationListener
Please select the affected platforms
- Android
- iOS (robovm)
- iOS (MOE)
- HTML/GWT
- Windows
- Linux
- MacOS
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 27 (10 by maintainers)
Commits related to this issue
- Downgrade gradle wrapper to v3.3 See: libgdx/libgdx#4855 — committed to mmorihiro/matchland by forestone23 7 years ago
Ok that was much more painful than it needed to be. Turns out you can just tell Android Studio to run a
JAR applicationand execute gradle:desktop:distbefore hand.For this approach set
Path to JARtoPROJECT_ROOT\desktop\build\libs\desktop-1.0.jarandWorking Directorythat same as you would for running an application. Lastly in theBefore launchat the bottom I added a gradle task with projectYOUR_GAME:desktopand taskdesktop:dist.Found the issue (it’s not related to the Reddit post described in Issue Details). Setting Gradle wrapper to version 3.3 fixes it (it took me a bit to find out because Gradle version changes were not being applied immediately). On Gradle 3.5.1 or 4.0.2 the game doesn’t launch on Desktop from the IDE neither on Android Studio nor Idea both on Windows and Mac even if it does from gradlew using console.
Just for clarity, you need to add a new run configuration, you can’t modify your existing one since it isn’t the proper type.
Run/Debug Configurationspage.JAR Application.Path to JARandWorking directoryas above.Before launchgradle task as above.