Thursday, February 19, 2015

Testing libgdx projects on the desktop while using Android Studio

If you have tried to use libgdx with Android Studio and found that you are unable to run the Desktop build, I would like to inform you that it now indeed possible, just takes a few more steps than running the android build.

First in Android-Studio click on the Gradle tasks bar at the right side of the screen. Then click the little arrow on the left of your gradle project name under the All tasks category, scroll all the way down to the :desktop section and click on the right arrow on the left of :desktop, and again scroll down and find the run task and double-click on the run task.

This will attempt to run your desktop project. Provided you have no errors, you should see your libgdx game window appear just like it used to with the older style Eclipse based projects.

Now, once you have done this, you can click on the Run menu item in the main window menu bar and choose Edit Configurations.

You should now have a new Run/Debug Configuration under the Gradle section called yourprojectname:desktop [run]. You may use this new configuration to run your desktop project without needing to find the run task in the long list of tasks.

I hope that this little mini tutorial has helped you work more efficiently with libgdx and Android Studio. It certainly was a wonderful thing to find today for me, as I have been cursing out Android Studio for it's lack of desktop application support ever since I downloaded it.

I used to curse about libgdx adopting Gradle for it's projects, but now, I certainly agree that it was a good move, and that it makes things a lot simpler. It all needs better documentation though. Things like this should be available right in the setup docs, without having to dig into the software blindly and happen across the answer.

No comments:

Post a Comment