This page is deprecated.

Newer, simpler instructions can be found on
a new page on netbeans and libgdx
click to dismiss

Summary

2012-08-23: newer page.

Previously, I explained how to use libgdx with Netbeans. However it was just for developing and testing on the computer and it still used Eclipse for deployment on the android phone. In this article, I explain how to use only Netbeans even for 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).

Let's do it

Setup

I'm currently using Netbeans (7.0RC1) 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). I could not find the “gdx-invaders” tutorial anymore, so this time I will take the gdx-helloword-*-zip file from the download page of libgdx (in version 0.9 at the time of writing).

You obviously need the android SDK to be installed (I don't detail this). Also, you need to install the nbandroid plugin for Netbeans. Beware: their original update site is outdated, at the time of writing and you must use the one mentioned at the top of the page in italic. Apart from this you just need to follow their instructions (add update site and install new plugins).

Also, you must follow the instructions from the my previous article to create the Netbeans Desktop project (for running your application on your computer). Beware of the directory names as the tutorials might not be the same (invaders vs helloworld). After that, you should have your desktop project running with Netbeans.

Building the Android APK without Eclipse

I am supposing you have your Heeere directory with 3 projects: Eclipse Desktop, Eclipse Android, Netbeans Desktop. Now, just open Netbeans and create a new project (File ↦ New Project):

  • Choose “Android ↦ Android Project” and click next
  • For the project name you can choose gdx-helloworld-netbeans-android and use Heeere for the location
  • Put anything that is accepted as a package name, e.g. gdx.netbeans.android
  • You can leave the activity name untouched
  • Select a SDK, for example Google APIs... 2.2 (I choose 2.2 because I used to have a phone in 2.1 and libgdx seemed to drain battery even after quitting the application).
  • Hit “finish”

If you build this newly obtained project, it should compile properly and get cleaned of its error markers. Unfortunately, the “property” page of the Android projects under Netbeans is not well populated. So, for now, we will need to do quite a lot of hacking using a terminal or equivalent. If you have Linux (or MacOS?), just follow the instructions. If you are under Windows (without cygwin), you will need to adapt these and maybe learn how to create symbolic links (under Windows).

We will keep the eclipse project intact and functional and just make the Netbeans project references its content. Let's go, here are the steps:

  • Move into the directory of the Netbeans project and set some variables (to simplify the rest):
    cd gdx-helloworld-netbeans-android
    e=gdx-helloworld-android
    nb=gdx-helloworld-netbeans # your Netbeans Desktop project
  • Link things to the other projects (some stuffs from the Eclipse project and the jar of the Netbeans Desktop project):
    rm -f AndroidManifest.xml ; ln -s ../$e/AndroidManifest.xml
                                ln -s ../$e/assets
    rm -rf res/               ; ln -s ../$e/res
    rm -rf src/               ; ln -s ../$e/src
    
    cd libs
     ln -s ../../$e/libs/* ./
     ln -s ../../$nb/dist/$nb.jar
    cd ..

That's it!

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

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.