Saturday, October 17, 2015

LibGDX: howto import a project in Eclipse from GitHub

The goal of this short tutorial is to explain how to import a LibGDX project from GitHub in Eclipse, using Gradle tool.
I am using Eclipse Mars (4.5.1) and Gradle 2.4.


SDK not defined

First, you can download a LibGDX project from GitHub, for example

git clone -b dev https://github.com/mytechpg/libgdx-samples.git

and then you can try to import test_viewport project.
It includes also an Android version and it is necessary to add the file local.properties that specifies the path of your Android SDK.
For example, my file content is:

# Location of the android SDK
sdk.dir=/home/andrea/bin/android-sdk-linux

You have to create this file because the .gitignore created automatically by LibGDX gradle procedure includes also local.properties file.

If you don't create the file, during the import you can't correctly load your projects and at the end of the import procedure you can see this error message:


Android version

If during the gradle import you see this error:

or 


android/build.gradle:

buildToolsVersion "20.0.0"
compileSdkVersion 21

You have to modify these values with versions available in your SDK (or add the required version to the SDK).

Build Android vresion error

Then, if you are still not able to build the Android project and the error is:

The import android.os.Bundle cannot be resolved

You have to open the properties of your project and then select a build target.


For example, you can select the first line, Android 4.1.2 and then press ok.
Now you are able to build and run you project on an Android emulator!

No comments:

Post a Comment