Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programs run fine with LibGDX -desktop but not LibGDX - Android?

So I have just set up Eclipse to work with LibGDX using Gradle. After I installed I noticed there was a problem with the Android package, there was a red cross next to the package. When I opened it further there was a red cross next to src then com.myname.game.android and then in AndroidLauncher.java. When I opened the AndroidLauncher.java, this was the code I got:

package com.faturbansloth.game.android;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.faturbansloth.game.MyGame;

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new     AndroidApplicationConfiguration();
        initialize(new MyGame(), config);
    }
}    

When I looked at the errors in he code of AndroidLauncher.java they were saying:

-The type android.os.Handler cannot be resolved. It is indirectly referenced from 
required .class files 
-The import android.os.Bundle cannot be resolved
-Multiple markers at this line
- The type android.app.Activity cannot be resolved. It is indirectly referenced from 
 required .class files
- The hierarchy of the type AndroidLauncher is inconsistent
-Bundle cannot be resolved to a type   

I am using SDK Manager 22.6.2 with the newest Gradle plugin for Eclipse. I have JRE 8 and JDK 7. Is there anyway to fix this problem? Thanks in advance.

like image 957
PixelPuppet Avatar asked Apr 15 '14 21:04

PixelPuppet


People also ask

Do you need Android SDK for libGDX?

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.

Does libGDX use Java?

libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux, macOS, Android, your browser and iOS.

Is libGDX free for commercial use?

LibGDX is a cross-platform 2D/3D game development environment, which was written in Java/C/C++ language based on Apache License 2.0 Agreement. It's free for commercial and non-commercial use and hosted on GitHub.


2 Answers

There was no Android Version selected by default, so go: Project -> Properties -> Android -> Project Build Target and select your preferred version

like image 149
Roy Avatar answered Nov 14 '22 20:11

Roy


I have no idea why this works but it does for me. I installed the ADT plugin, refreshed the android section and the red cross disappeared.

Refer to the section under "Download the ADT Plugin" to install the ADT plugin. http://developer.android.com/sdk/installing/installing-adt.html

After that, go to Eclipse > Package Explorer > Left click on Project-android > Select Refresh.

like image 26
ikikika Avatar answered Nov 14 '22 20:11

ikikika