Prerequisites for installing and configuring
Before you can start writing any application or game with Libgdx, you need to download and install the library and also some additional software.
Java Development Kit (JDK)
Due to the fact that Libgdx is a framework based on Java, it is necessary to download the JDK. The software is freely available on Oracle's website at http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Click on the DOWNLOAD button to start downloading the latest JDK.
Note
It is important to choose the JDK instead of the JRE package. The reason is that the JDK package contains both, the Java Runtime Environment (JRE ) to run java applications and everything else that is required to develop them.
You will have to accept the license agreement and choose the version that is appropriate for your platform. For example, if you are using a 64-bit version of Windows, choose the download labeled as Windows x64.
To install the JDK, simply run the downloaded installer file (for example, jdk-7u11-windows-x64.exe
) and follow the instructions on the screen.
In the welcome screen of the installer, click on Next > to continue.
Then, keep all features selected as to be installed and click on Next > again to continue.
Once the installation has been completed, click on the Close button to exit the installer.
Eclipse – Integrated Development Environment (IDE)
The next step is to download and install Eclipse, a freely available and open source IDE for developing applications in Java. Go to http://www.eclipse.org/downloads/ and choose Eclipse IDE for Java Developers to download for the platform you are using.
Once the download has finished, extract the archive to C:\eclipse\
.
Downloading Libgdx
Next, go to
http://code.google.com/p/libgdx/downloads/list and choose the file libgdx-0.9.7.zip
to download Libgdx.
Note
At the time of writing this book, the latest stable version of Libgdx is 0.9.7. It is recommended to use the same version while working with this book.
In the meanwhile, create a new folder in the root folder of your C drive with the name libgdx
. Once the download has finished, move the archive to C:\libgdx\
. Then, open the archive and extract the .jar-File gdx-setup-ui
to C:\libgdx\
. The extracted program will help you later with creating new game projects in an easy to use GUI.
Installing Android SDK
The Android mobile OS is one of Libgdx's supported target platforms. Before you can create Android applications, you have to download and install the Android SDK. Go to http://developer.android.com/sdk/index.html and click on the Download the SDK Tools for Windows button. Should you be using an OS other than Windows, you will have to scroll down a bit further, click on Download for other platforms and choose the appropriate platform.
Once the download has finished, run the installer (for example, installer_r22.0.4-windows.exe
) and follow the instructions on the screen.
You may see the following screen when you try to install the Android SDK. The installer cannot find the JDK although you have already installed it.
You need to set the value of the environment variable JAVA_HOME
to the installation path of the JDK. To find the correct path go to C:\Program Files\Java\
. You should see a folder starting with jdk
in its name. Take the full name of this folder (here, jdk1.7.0_11
) and append it to its path.
The complete path should now look similar to this: C:\Program Files\Java\jdk1.7.0_11
.
Now you have to set the environment variable. Click on the Windows Start button and right-click on Computer. Then click on Properties to open the control panel system window.
Click on Advanced system settings on the left side of the window.
The System Properties window will appear. Next, click on the Environment Variables … button.
The Environment Variables window will appear. Click on the upper New … button that corresponds to User variables for <USERNAME>
. A window with the title New User Variable will appear.
Now, fill in the two text fields. Use JAVA_HOME
in the Variable name: field and the JDK's path you found out earlier in the Variable value: field.
Great! Now your system is prepared for the Android SDK installer. Please make sure to exit the Android SDK installer in case it is still running to let the change take effect. You should be presented with the following screen after the installer has restarted.
Now, back in the Android SDK setup, click on Next > to continue the installation.
The following screen will ask you to choose the users for which the Android SDK should be installed. Usually, the suggested selection Install just for me is perfectly fine, so just click on Next > to continue.
Now, choose the installation location on your computer. You can safely keep the suggested location and click on Next > to continue.
After that, you will be asked to choose a start menu folder. Again, you can safely keep the suggestion and click on Install to start the installation process.
After the installation is complete, click on Next > to continue.
Once the installation has finished, you can choose to start the Android SDK Manager. Leave the checkbox Start SDK Manager (to download system images, etc.) enabled and click on Finish to start the manager.
The Android SDK Manager enables you to download system images for the specific API levels you want to be able to develop applications for. For up-to-date and detailed information about Android API levels, check out the following link at http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels.
Now, choose at least Android 2.2 (API 8) and/or any other higher API levels you may need and click on the Install packages … button to automatically download and install all relevant files. The reason why we want to use at least API level 8 is that earlier versions before Android 2.2 do not support OpenGL ES 2.0, which we will need in later chapters. Using a certain API level also allows you to control the range of devices that will be able to see and install on your application via the Google Play Store.
Once the download and installation process has finished, close the Android SDK Manager window.
Running Eclipse and installing plugins
Great! You are almost done setting everything up. The remaining steps involve running Eclipse for the first time and installing two important plugins, which are required to develop applications for Android and HTML5/GWT with Eclipse.
Open Windows Explorer and go to the location where you extracted Eclipse (here, C:\eclipse\
) and simply run the program by double-clicking on the executable called eclipse
.
Eclipse will ask you to select a so-called workspace. This is the folder where all your projects will be saved in. We want to use the folder C:\libgdx\
we created a bit earlier.
Select the Use this as the default and do not ask again checkbox, if you do not want to see this dialog every time you start Eclipse. To proceed, confirm the dialog by clicking on the OK button.
The first time Eclipse is started with a new workspace, it will greet you with a welcome screen. Simply click on the small cross (x) of the Welcome tab to close it.
You should see the standard view of Eclipse now, which is also called the Java Perspective . On the left-hand side you can see the Package Explorer section. This is where you will see and manage your different projects. That is all you need to know about Eclipse for the moment.
In case you have never worked with Eclipse before, it may seem quite overwhelming with all these windows, toolbars, huge context menus, and so on. However, rest assured that all steps will be discussed in detail as required to make it easy for you to follow.
To install new plugins, go to the menu bar and click on Help, and then Install New Software…. This will open the Install window where you can type special repository URLs to browse for new plugins. Google provides a list with such URLs at https://developers.google.com/eclipse/docs/getting_started. You have to choose the correct URL that corresponds with your Eclipse installation.
At the time of writing this book, Eclipse 4.2.1 (Juno) was the most current version available. According to Google's website, their suggested URL for our version is http://dl.google.com/eclipse/plugin/4.2.
Type the URL into the text field that is labeled Work with: and press return to let Eclipse request a list of available downloads. Select everything in the list that is shown in Developer Tools to add support for Android applications. Then, select everything in Google Plugin for Eclipse (required) to install the required Eclipse plugin. Lastly, select Google Web Toolkit SDK 2.5.1 in SDKs to add support for HTML5/GWT applications and click on Next > to continue.
Now, click on Next > to start the installation.
You will now be prompted to accept the terms of the license agreements by selecting the option I accept the terms of the license agreements. You have to do this before you can click on Finish to continue, as shown in the following screenshot:
The download process should only take a couple of minutes, depending on the speed of your network connection. When downloading has finished, Eclipse will show a security warning that you are about to install unsigned content and wants to know whether it should continue or abort. There is always a potential risk of installing malicious software. However, in this case the download is provided by Google, a well-known company, which should be trustworthy enough. Click on the OK button to accept the warning and continue the installation, as shown in the following screenshot:
After the installation has finished, a final restart of Eclipse is required. Click on the Yes button to confirm the restart, as shown in the following screenshot:
Congratulations! You have just finished the installation of everything you will need to develop and build your own games with Libgdx.