Summary

It can be tedious to develop Android applications that uses OpenGL ES (like some games). The libgdx library makes it simpler. One of the features is that you can run your libgdx application not only on a phone (or emulator) but also on your desktop computer. The tutorials for libgdx are using mostly eclipse because of the first class android support with ADT (Android Development Tools).

This page is about creating a simple Netbeans project to develop your libgdx application. It explains how to use only Netbeans (if desired) even for developing and running your libgdx application on the phone. Actually, you can even use this for dual development, switching between Netbeans and Eclipse at will (e.g., for multi-author projects).

(there are old deprecated pages on this site: here and here)

Let's do it

Download and Tools Setup

I'm currently using Netbeans (7.2, which is awesomly faster) but it should work with most versions. If you don't already have it, you need to install Netbeans (the “Java SE” version should be enough). Now download the latest libgdx from their download page (in version 0.9.6 at the time of writing). Also, for the demos, you need to get the code from github as a zip of the latest version (or just clone if you know what it means).

You obviously need the android SDK to be installed (I don't detail this). Also, you need to install the nbandroid plugin for Netbeans. Just follow their instructions (add update site and install new plugin).

Directories and Projects

Make a directory, let's name it Heeere. Just unzip the libgdx zip (e.g., libgdx-0.9.6.zip) file in Heeere/libgdx. You should get a lot of files (jar files, folders, etc) into the folder. Also unzip the github code (e.g., libgdx-libgdx-391fc93.zip) file in Heeere. You should get many files within a subfolder (e.g., libgdx-libgdx-391fc93).

Now we will copy one demo project so that we can mess up with it as much as we want. For example I copied Heeere/libgdx-libgdx-391fc93/demos/very-angry-robots into Heeere. This way, I get a folder Heeere/very-angry-robots that contains two subfolders (one is the eclipse project, the other is the android project).

Now with Netbeans

Just open Netbeans and create a new project:

  • Choose “Java->Java App.” and click next
  • For the project name you can choose “very-angry-robots-netbeans” and use Heeere/very-angry-robots for the location
  • Uncheck the “use dedicated folder for storing libraries” box
  • Uncheck the “create Main class” box
  • Hit “finish“

Now we have to setup the project to reuse source from the other (eclipse) project and libgdx libraries. Right click on your project and select “properties”:

  • In “Source Package Folders”, click “add folder” and choose the Heeere/very-angry-robots/very-angry-robots/src folder. Important: at the bottom, set the “Source/Binary Format” to “JDK 6” (this is to prevent a silent problem with android toolchain and jdk 7).
  • Still in this window, go to the “Libraries” category (on the left) and click “add JAR/folder”. Browse to Heeere/libgdx and select all the jars but gdx-backend-gwt.jar (with shift or control), select the “relative path” option and click “Ok”.
  • Still in the properties window, go to the “Run” category. In “Working Directory” put ../very-angry-robots and hit “Ok”.

Run the desktop version!

Now you can run your program, for example by hitting F6 and choosing the main class (only the first time). OK, this “very-angry-robots” is designed for a touch screen so it was not the best for the desktop example :).

Build and Run the Android version!

At this point, you have your Heeere/very-angry-robots directory with 3 projects: Eclipse, Android, Netbeans. Now, just open Netbeans and open a project (File ↦ Open Project) and select Heeere/very-angry-robots/very-angry-robots-android

Some libraries needs to be copied into the android project. First you have to build the jar for your netbeans project by right clicking on the netbeans project “very-angry-robots-netbeans” and do “Build”. Now you have to copy (or ideally do symbolic links to avoid copying every time) into Heeere/very-angry-robots/very-angry-robots-android/libs 3 files: Heeere/very-angry-robots/very-angry-robots-netbeans/dist/very-angry-robots-netbeans.jar, Heeere/libgdx/gdx-backend-android.jar and Heeere/libgdx/gdx.jar.

Now you can run your program on your phone from Netbeans, for example by hitting F6 and choosing your device (that you first adequately plugged on usb).

Remark: you might now need to copy libgdx.so in libs/armeabi for it works (thanks to Philippe Van Der Gucht for the hint).

libgdx on android with netbeans

I hope this was useful.
In case of problems, questions or remarks, just contact me at click-me ;-p @nospam.com.