LibGDX with IntelliJ IDEA CE 16

IntelliJ IDEA

This article will walk through downloading the nessary files and creating a inital libGDX game project. IntelliJ IDEA requires the Java JDK 8+, install this before moving forward.

Lets get the latest IntelliJ IDEA CE package from the JetBrains website. Once downloaded. Extract the file and move it to the /opt directory.

Next, you’ll need to change the ownership and create a symlink.

Finally, run /opt/intellij/idea.sh. On first run, it will ask you to create an optional shortcut.

Android SDK

Go to the Android developers website and download the latest SDK Command Line Tools. You won’t need the full Android Studio IDE.

Once downloaded, extract and move to the /opt/android-sdk directory.

You’ll now run the SDK Manager and download the Android developer files as needed.

This will open the Android SDK Manager interface. First, click on the Deselect All option as the Manager will by default select some System Images that aren’t needed.

The Android SDK Manager auto selecting System Images

Select the newest Android SDK Tools, Android SDK Platform-tools, and Android SDK Build-tools.

Next, go to the LibGDX Versions page to view the latest version of the Android SDK that libGDX has been tested with.

Go ahead and select the Android SDK Build-tools and SDK Platform in question.

Android SDK Manager Platform

Once the packages have been selected, click on Install packages… and accept the License agreement.

LibGDX

LibGDX Setup App automatically creates a IntellJ IDEA Project. Lets grab this application. Go to the LibGDX Download page and download the latest version of the Setup App. To Keep things clean, download to ~/projects/libgdx.

Once downloaded, run the application

LibGDX Project Generator

Here you’ll setup the project information and Gradle configuration.

  • Name: Name of your Game Project in Camel Case
  • Package: Name of your game pacakge in Java package naming convensions
  • Game class: Name of the main java class in Pascal Case
  • Destination: place the project files in /home/USERNAME/projects/libgdx/<Name>
  • Android SDK: The root location of the Adroid SDK, in this case, /opt/android-sdk

You may add or remove any add-ons or extensions at this point. You may also do this afterwards by editing the build.gradle files.

Click Generate to create the project files. You may receive a few popups before you can continue.

LibGDX Android Build Tools Warning

Clicking Yes here will use the Latest Build Tools in the Android SDK folder. Clicking No will select the version LibGDX was tested against.

LibGDX Android API Warning

LibGDX Android API MessageSimilarly, if you have a newer version of the Android API, libGDX will request which API version you want to use. Here, if you select No, libGDX will use the API version it was tested against.

Note, if you do select No on either of these options, verify you have the SDK packages libGDX is requesting installed. Gradle is unable to download the Android packages if they are missing.

Importing the Project

Before importing a libGDX project, you will want to verify the SDKs are defined in IntelliJ. At the Welcome Screen, select Configure > Project Defaults > Project Structure.

IntelliJ IDEA Default Project Structure

Verify the Java and Android SDK are defined. If not, create them now.

Lets now import the Gradle script to build the game project. Click on the Import Project and locate the build.gradle file in the root of your game project folder.

IntelliJ IDEA Import

The Import Project from Gradle screen pops up. Nothing needs to be edited here. Click on OK.

IntelliJ IDEA Import Project from Gradle

If you receive the error below, there are two things you’ll need to check.

IntelliJ IDEA Import Error

  1. Verify the Android API in question is installed.
  2. Verify the Android SDK is defined in the Project Structure.

These steps were described in the previous sections, please review them if necessary.

Once Successful, it will take few moments for Gradle to download and build the project files. If any pop ups come up at this point, click OK to move forward.

Bonus: Test Desktop Build

To test your game on the desktop, you’ll need to setup the build process for the desktop. On the Toolbar, click on Run > Edit Configurations…. There are two ways to build a desktop application.

Gradle

  • Click + > Gradle
  • Name: Desktop
  • Gradle Project: Project path
  • Taskdesktop:run

IntelliJ Debug Configurations Gradle

Applciation

IntelliJ Debug Configurations Application

  • Click + > Application
  • Name: Desktop
  • Main classDesktopLauncher
  • Working Directory<Project_Path>/android/assets, or if no android sub project, then <Project_Path>/core/assets
  • User classpath of module: desktop