Search code examples
javaandroidlibgdx

Libgdx program running in Desktop but not on Android


The test program I got from libgdx run on Android so I think it can't be the ADT-Plugin or something like that. I don't change anything in the Android code and this is my core code:

package com.mygdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class MyGdxGame extends Game {
Stage stage;
private Skin skin;
private TextButton buttonPlay;
private Image red;
private Image green;
Boolean move=false;


@Override
public void create () {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("button.json"),
                new TextureAtlas(Gdx.files.internal("ButtonSkins/menu.pack")));
    buttonPlay = new TextButton("Start", skin);

    red = new Image (new Texture("ButtonSkins/menu_hintergrund.png"));
    green = new Image (new Texture("ButtonSkins/menu_hintergrund2.png"));
    red.setHeight(stage.getHeight()/2);
    red.setWidth(stage.getWidth());
    green.setHeight(stage.getHeight()/2);
    green.setWidth(stage.getWidth());
    green.setPosition(0, stage.getHeight()/2);
    buttonPlay.setWidth((float) (red.getWidth()/2.45));
    stage.addActor(red);
    stage.addActor(green);
    stage.addActor(buttonPlay);
    buttonPlay.moveBy(stage.getWidth()/2-buttonPlay.getWidth()/2, stage.getHeight()/2-buttonPlay.getHeight()/2);
    buttonPlay.addListener(new ChangeListener(){
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            move=true;
        }           
        });
}

@Override
public void render () {
    Gdx.gl.glClearColor(150,110, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if(move){
    green.addAction(Actions.sequence(Actions.moveBy(0, 5)));
    red.addAction(Actions.sequence(Actions.moveBy(0, -5)));
    }
    stage.act();
    stage.draw();
}

@Override
public void dispose() {
    stage.dispose();
}

}

I really have no idea what I did wrong can someone please help me?

Catlog:

12-10 00:22:45.920: D/dalvikvm(725): Not late-enabling CheckJNI (already on)

12-10 00:22:47.940: D/dalvikvm(725): Trying to load lib /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88

12-10 00:22:47.940: D/dalvikvm(725): Added shared lib /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88

12-10 00:22:47.940: D/dalvikvm(725): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88, skipping init

12-10 00:22:48.210: D/AndroidRuntime(725): Shutting down VM

12-10 00:22:48.210: W/dalvikvm(725): threadid=1: thread exiting with uncaught exception (group=0xb2a80d70)

12-10 00:22:48.260: E/AndroidRuntime(725): FATAL EXCEPTION: main

12-10 00:22:48.260: E/AndroidRuntime(725): Process: com.mygdx.game.android, PID: 725

12-10 00:22:48.260: E/AndroidRuntime(725): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.access$800(ActivityThread.java:138)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.os.Handler.dispatchMessage(Handler.java:102)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.os.Looper.loop(Looper.java:136)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.main(ActivityThread.java:5026)

12-10 00:22:48.260: E/AndroidRuntime(725):  at java.lang.reflect.Method.invokeNative(Native Method)

12-10 00:22:48.260: E/AndroidRuntime(725):  at java.lang.reflect.Method.invoke(Method.java:515)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

12-10 00:22:48.260: E/AndroidRuntime(725):  at dalvik.system.NativeStart.main(Native Method)

12-10 00:22:48.260: E/AndroidRuntime(725): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.Activity.performCreate(Activity.java:5242)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)

12-10 00:22:48.260: E/AndroidRuntime(725):  ... 11 more

12-10 00:23:36.730: D/dalvikvm(844): Trying to load lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70

12-10 00:23:36.750: D/dalvikvm(844): Added shared lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70

12-10 00:23:36.760: D/dalvikvm(844): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70, skipping init

12-10 00:23:36.830: D/AndroidRuntime(844): Shutting down VM

12-10 00:23:36.840: W/dalvikvm(844): threadid=1: thread exiting with uncaught exception (group=0xb2a80d70)

12-10 00:23:36.900: E/AndroidRuntime(844): FATAL EXCEPTION: main

12-10 00:23:36.900: E/AndroidRuntime(844): Process: com.mygdx.game.android, PID: 844

12-10 00:23:36.900: E/AndroidRuntime(844): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.access$800(ActivityThread.java:138)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.os.Handler.dispatchMessage(Handler.java:102)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.os.Looper.loop(Looper.java:136)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.main(ActivityThread.java:5026)

12-10 00:23:36.900: E/AndroidRuntime(844):  at java.lang.reflect.Method.invokeNative(Native Method)

12-10 00:23:36.900: E/AndroidRuntime(844):  at java.lang.reflect.Method.invoke(Method.java:515)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

12-10 00:23:36.900: E/AndroidRuntime(844):  at dalvik.system.NativeStart.main(Native Method)

12-10 00:23:36.900: E/AndroidRuntime(844): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.Activity.performCreate(Activity.java:5242)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)

12-10 00:23:36.900: E/AndroidRuntime(844):  ... 11 more

Solution

  • If you are using the emulator to test you shouldn't, but in case you can't use a phone to test it you can try this: libgdx android failed on launch .

    Also it might happen that you are testing the desktop in Windows and that the external directory or filename doesn't case match which in Windows doesn't cause any trouble, but in Unix the filenames and directory names are case sensative so Teste.jpg is different from teste.jpg

    Source: https://stackoverflow.com/a/27125547/1779833