LibGDX with IntelliJ IDEA CE 16
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
tar -zxf ideaIC-2016.VERSION.tar.gz
sudo mv idea-IC-VERSION /opt/
Next, you’ll need to change the ownership and create a symlink.
sudo chown -R root.root /opt/idea-IC-*
sudo ln -s /opt/idea-IC-<VERSION> /opt/intellij
/opt/intellij/idea.sh. On first run, it will ask you to create an optional shortcut.
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
tar -zxf android-sdk_VERSION.tar.gz
sudo mv android-sdk-tools /opt/android-sdk
chown -R root.root /opt/android-sdk
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.
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.
Once the packages have been selected, click on Install packages… and accept the License agreement.
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
Once downloaded, run the application
java -jar ~/projects/libgdx/gdx-setup.jar &
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
- Android SDK: The root location of the Adroid SDK, in this case,
You may add or remove any add-ons or extensions at this point. You may also do this afterwards by editing the
Click Generate to create the project files. You may receive a few popups before you can continue.
Clicking Yes here will use the Latest Build Tools in the Android SDK folder. Clicking No will select the version LibGDX was tested against.
Similarly, 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.
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.
The Import Project from Gradle screen pops up. Nothing needs to be edited here. Click on OK.
If you receive the error below, there are two things you’ll need to check.
- Verify the Android API in question is installed.
- 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.
- Click + > Gradle
- Name: Desktop
- Gradle Project: Project path
- Click + > Application
- Name: Desktop
- Main class:
- Working Directory:
<Project_Path>/android/assets, or if no android sub project, then
- User classpath of module: desktop