Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

26. March 2014


I am a big fan of LibGDX and a big hater of Eclipse.  This always put me in a bit of an awkward situation, as in order to use LibGDX you basically had to use Eclipse, at least if you wanted cross platform support.  You could get IntelliJ to work, but it required a heck of a lot of jumping through hoops.  The reason Eclipse was basically forced upon you is because Google tied it’s tools pretty heavily to the Eclipse platform.  So if you want to use GWT ( for HTML target ) or Android, Eclipse was by far the easiest path.  Fortunately LibGDX recently announced they moved their build system to Gradle. 


Now let’s take a look at how you create and execute a LibGDX project in Eclipse.  First and foremost, grab a new release of LibGDX.


Next we want to generate our project.  You need gdx-setup.jar, you can download it here or find it in the lightly release of LibGDX.  Simply double click the jar to run it.  You can also run it from the command line, but we will only use the GUI in this example.




It’s like a stripped down version of the old setup tool, enter the name, package and class name ( following Java naming rules ) and click generate.


Configuring Android


You need to have the Android SDK installed to continue.  I recommend installing the stand-alone version of the SDK instead of the ADT bundle ( which is Android SDK + Eclipse ).  You can download the Android SDK here.  The download can be a bit tricky to located, Scroll down and locate “DOWNLOAD FOR OTHER PLATFORMS”, then locate SDK Tools only and download the appropriate package:




Extract that archive somewhere. 

At this point ( I am not sure its required, but it’s a good idea ), set the environment variable ANDROID_HOME and point it to this folder.


Now open up this folder and located SDK Manager:



Run it.  Let it install/un-install whatever it wants to do to make sure you are current.


The next step is very important.  You need to install the build tools version that LibGDX expects.  Right now I believe that version is 19.0.3.  The Gradle build process will fail if these tools are not installed.




Configuring IntelliJ


Make sure you have version 13 or higher.  You can download it here.  Community edition is fine, in fact, not much of the paid version is of use to a game developer.  Download and install IntelliJ 13.x if you haven’t already.


Anyways, now that we have fired up IntelliJ, we have a bit of configuration to do before we continue.  We need to setup our JDK and Android SDK in IntelliJ.  If you haven’t already, install and configure the Java 7 JDK.


This part is going to be a bit awkward, but it should only happen the first time.


Run IntelliJ.

In the welcome dialog, select Import Project



Navigate to the directory you created your project in earlier and select build.gradle from the root directory:



Click OK.

In the next dialog, accept the defaults and click OK.



Gradle is now going to build your project… or at least try.

Gradle downloads all the required components, so this could take a while.   Or it should, but truth is, its going to explode in a horrible state of explosionness.  Look for an error like this;



Don’t worry over much, it’s just that IntelliJ doesn’t have a clue where your JDK and ADK are.  Let’s fix that now.


In the Project View (ALT + 1 if missing), right click the root project and select Open Module Settings:



In the resulting dialog select SDKs then click +.



Select JDK



Navigate to the location you installed your JDK.


Next click + again, and this time select Android SDK.  Select the Android SDK location and click OK.

This time you also have to pick the version:



Now there is a possibility you have a wrongly configured JDK at this point too:


If you have an entry other than the ones you created, select it and then hit the – button.


OK, SDK’s are now configured.


Now lets re-import the project.  Select File->Import Project and pick the .build file in the root of your project again.  When prompted:


Select “This Window”.


Now your project should load without errors.  You should never have to perform the above steps again, unless you change JDK or Android SDK versions.


Running the Desktop Project


You have a one time configuration to run each project type.  Let’s start with the Desktop project:

Select Run->Edit Configurations…



If an entry for Desktop doesn’t already exist, select the + icon.



Select Application:



Now configure the project like so.  Name it then select DesktopLauncher as the Main Class, the Android\assets folder for the working directory and desktop for the classpath value.




Once again, its very important when selecting the working directory, make sure to select the assets folder in the android project!



Now select Run->Run Desktop and voila:



Running the Android Project


Once again select Run->Edit Configurations.

If an Android project doesn’t exist, select the + icon and select Android Application.



In the configuration, name it, select Android for module and optionally pick USB Device under target device.  Unless of course you are crazy enough to actually use the horrific Android emulator that is!



Now select Run->Run Android to run on an Android device.  The application will be deployed to your device and you should see Logcat information in IntelliJ




Running the iOS Project


Ok… you need a Mac to do this part and I don’t currently have my Mac with me.  So… coming later.



Running the GWT ( HTML ) Project


If there is an area you are going to have trouble with, this is the one.  It’s somewhat normal though, I’ve had a lot of fights with GWT tooling thus far.


The project is the same Run->Edit Configurations:

This time select Gradle as the project type.



Now configure the following, set the Name, select the gradle project ( details below ), click Single Instance Only and task to superDev:




When setting the gradle project, be sure to select the project in the gwt folder.



Now click Run->Run HTML.


It will churn away for a few moments, then you should see:



Look for the URL in the results.  Open this in a browser to run your app.


In all honesty, this currently simply doesn’t work for me right now.  Currently I get:



Frankly I have had nothing but trouble with GWT and superDEV, so I really cant be bothered fixing this at the moment.  If I do come up with a solution, I will post it here.



Ok, I have a solution to the GWT problems, and it was mostly me, but partially a lack of intuitiveness.

To see your application, once you run the project open a browser window and go to localhost:8080/gwt

Then you should see:



There you now have a working project running in IntelliJ now.  Much of that was one time, so at the end of the day, after the first time, setting up a new project in IntelliJ is just as fast as an Eclipse one.  YAY, no more Eclipse!

Programming ,

blog comments powered by Disqus

Month List

Popular Comments