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

Most upvoted comments

Ok that was much more painful than it needed to be. Turns out you can just tell Android Studio to run a JAR application and execute gradle :desktop:dist before hand.

For this approach set Path to JAR to PROJECT_ROOT\desktop\build\libs\desktop-1.0.jar and Working Directory that same as you would for running an application. Lastly in the Before launch at the bottom I added a gradle task with project YOUR_GAME:desktop and task desktop: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.

  1. Open the Run/Debug Configurations page.
  2. Create a new Configuration of type JAR Application.
  3. Set the Path to JAR and Working directory as above.
  4. Add the Before launch gradle task as above.