Cross-Platform Games and Applications with libGDX – Setup

Travis O'Brien

Setup LibGDX with IntelliJ

This tutorial will show how to set up and run libGDX applications using IntelliJ for desktop and Android applications. libGDX is a Java application development framework with a unified API that allows the user to seamlessly compile to multiple platforms.

I will be using the library with IntelliJ, a powerful Java IDE to help manage the project throughout it’s development.

Download and install the Community version of IntelliJ

Next, Install the Android SDK.

Finally, download and run the libGDX Setup App

Setting up LibGDX

In the libGDX Setup App, fill out the required forms for generating a new libGDX project. Leave everything at their default values except for the destination and Android SDK paths.

libGDX Project Setup

Under the Sub Projects and Extensions tabs are where you specify which platforms to compile and which libraries to include in the project.

These settings are not permanent and you will always have the option to change them.

NOTE: This tutorial is aimed at developing applications for Desktop and Android. Compiling to Desktop allows for fast prototyping and I want to avoid using any emulators as much as possible. There’s always the option of compiling straight to an android device, but it will be slower than compiling to desktop.

Under Extensions, there are a plethora available for use. Hovering over each extension’s check box will show a tool-tip giving a description of that extension. Only select the extensions used by the application. Otherwise they will unnecessarily increase the file size of the application.

Sub Projects and Extensions

Most applications (especially games) will use:

  • Freetype for text and fonts.
  • Tools for efficient texture packing
  • Box2d for physics.

The last step before generating the project is to click the Advanced button and make sure IDEA is selected. Click Save and then Generate. Because libGDX uses Gradle to manage all dependencies, the setup application will download all required dependencies for this project. Once everything downloads, you can open the project with IntelliJ.

libGDX Project Setup Advanced Settings

Setting up IntelliJ

Open the generated IntelliJ project file and when prompted to link Gradle do so. In the Import Project from Gradle window, set the path to the JVM and when prompted Open exisiting project.

Import dialogue

There are a more steps needed before the application can run.

In the upper right corner of the screen, click the drop down arrow and select Edit Configurations…

Run/Debug Configurations

A new Run/Debug Configurations window will appear. In the upper left corner of the screen, select the green + symbol, and in the Add New Configuration popup select Application.

Add New Configuration

You now have a new configuration which will handle how the file will compile for Desktop.

Now, There’s three adjustments you need to make.

Make sure the Configuration tab is selected and under Main class click the three ellipses. A new window will appear, click Choose Main Class, select DesktopLauncher and click OK.

Choose Main Class

Under Use classpath of module, click the drop down arrow and select desktop.

User classpath of module

Next set the Working Directory to store al all assets of a project, such as textures, audio, JSON files, etc.

Under Working directory click the three ellipses, select the project/android/assets folder, and click OK.

Working directory

Everything is now setup in Run/Debug Configurations, so click Apply and then OK. The application can now be run by clicking the green Play button.

libGDX Sample Application

You are now ready to get started with developing applications with libGDX!

Deploy Application to Android

To deploy an application to Android, you need create a ‘Signed APK’. Open the Build -> Generate Signed APK… menu item and a new Generate Signed APK window will appear.

enter image description here

If you have never created a signed APK before, then you will need to add some details.

  • Key store path: Path to key store location.
  • Password: Password for key store.
  • Alias: Alias of key.
  • Password: Password for key.
  • Validity: For how many years is the key valid.
  • Certificate: Enter any values as needed.

New Key Store

NOTE: This information should be kept private as this is your personal APK signature. Don’t forget the details or where you save the key.

After clicking OK, You will be back to Generate Signed APK and can select the type.

IMPORTANT: When deploying a final release of an application, make sure to select build. Releasing an application signed with debug may cause unnecessary performance penalties.

After generating the signed APK, copy it to and launch it from an Android phone.

NOTE: You may need to enable access to unknown APK files.

Debugging an APK File

Instead of generating an APK file and sending it to an Android phone, you can run the application directly from IntelliJ and have it run on you phone.

Create a new Run/Debug Configuration setup and set Module to the project’s android module. Now you can launch the application on an Android device or in the emulator.

Swapping between Desktop and Android for Debugging

Now you have two Run/Debug Configuration options, each is ready to target their specific platform. Switch between the two setups to choose which platform to run the application from.


libGDX is a powerful tool for developing cross-platform applications and games. In this tutorial I showed you how to setup an IDE to get started developing with the framework and in the next installment I’ll get stuck into some actual coding.

In the meantime, any questions or comments, let me know below.

CSS Master, 3rd Edition