androidlibgdxscene2dskins

Android application crashes when loading uiskin.json


I am having problems loading the uiskin.json file into my Android Application. This is a piece of test code I wrote:

private TextureAtlas buttonsAtlas;

private Skin skin;
private Skin buttonSkin;

private Stage stage;

private TextButton textButton;
private ImageButton imageButton;

@Override
public void create () {
    stage = new Stage();
    buttonsAtlas = new TextureAtlas(Gdx.files.internal("buttons.pack"));
    buttonSkin = new Skin(buttonsAtlas);

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    textButton = new TextButton("test", skin);
    textButton.setPosition(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);

    imageButton = new ImageButton(buttonSkin.getDrawable("imageUp"), buttonSkin.getDrawable("imageDown"));
    imageButton.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

    stage.addActor(imageButton);
    stage.addActor(textButton);


    Gdx.input.setInputProcessor(stage);

}

@Override
public void render () {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}

This code works perfectly when launched from the desktop launcher. However, when the android file is exported, and the APK is loaded into an emulator (I am using BlueStacks) the program simply crashes.

When I comment these lines

  //  skin = new Skin(Gdx.files.internal("uiskin.json"));
  //  textButton = new TextButton("test", skin);
  //  textButton.setPosition(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);

and then export the application to Android, it runs just fine on the emulator (so no problems when I use the .pack file with buttons that I created and load that into a skin).

I narrowed down the problem to this line: skin = new Skin(Gdx.files.internal("uiskin.json"));

I'm using the uiskin.json file and the associated uiskin.atlas and uiskin.png files from GitHub: uiskin files.

Any thoughts on this? I find it weird that I can't seem to use skins in an Android application. Any help is welcome, thanks.



EDIT I finally managed to get my emulator running from inside Eclipse, so I could provide the stacktrace. I ran the program that I used above and exported the LogCat report to a text file, which I have given below:

09-10 22:42:10.116: I/art(1876): Not late-enabling -Xcheck:jni (already on)
09-10 22:42:10.337: D/(1876): HostConnection::get() New Host Connection established 0xb451a670, tid 1876
09-10 22:42:10.603: I/AndroidInput(1876): sensor listener setup
09-10 22:42:10.664: D/OpenGLRenderer(1876): Render dirty regions requested: true
09-10 22:42:10.689: D/Atlas(1876): Validating map...
09-10 22:42:10.793: I/art(1876): Background sticky concurrent mark sweep GC freed 1995(134KB) AllocSpace objects, 0(0B) LOS objects, 21% free, 489KB/623KB, paused 34.847ms total 239.093ms
09-10 22:42:10.818: D/(1876): HostConnection::get() New Host Connection established 0xa6e67fa0, tid 1897
09-10 22:42:10.879: I/OpenGLRenderer(1876): Initialized EGL, version 1.4
09-10 22:42:10.957: I/art(1876): Background partial concurrent mark sweep GC freed 133(18KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 471KB/983KB, paused 37.420ms total 136.703ms
09-10 22:42:10.958: D/OpenGLRenderer(1876): Enabling debug mode 0
09-10 22:42:10.977: W/EGL_emulation(1876): eglSurfaceAttrib not implemented
09-10 22:42:10.977: W/OpenGLRenderer(1876): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e8ca80, error=EGL_SUCCESS
09-10 22:42:11.078: D/(1876): HostConnection::get() New Host Connection established 0xa6e678f0, tid 1894
09-10 22:42:11.133: W/GL2JNIView(1876): creating OpenGL ES 2.0 context
09-10 22:42:11.493: I/GL2(1876): all initialized 2
09-10 22:42:11.493: I/AndroidGraphics(1876): OGL renderer: Android Emulator OpenGL ES Translator (AMD Radeon 6600M and 6700M Series)
09-10 22:42:11.499: I/AndroidGraphics(1876): OGL vendor: Google (ATI Technologies Inc.)
09-10 22:42:11.504: I/AndroidGraphics(1876): OGL version: OpenGL ES 2.0 (4.5.13399 Compatibility Profile Context 15.200.1062.1004)
09-10 22:42:11.504: I/AndroidGraphics(1876): OGL extensions: GL_EXT_debug_marker GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8
09-10 22:42:11.504: E/EGL_emulation(1876): [getAttribValue] Bad attribute idx
09-10 22:42:11.504: E/EGL_emulation(1876): tid 1894: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
09-10 22:42:11.508: E/EGL_emulation(1876): [getAttribValue] Bad attribute idx
09-10 22:42:11.508: E/EGL_emulation(1876): tid 1894: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
09-10 22:42:11.508: I/AndroidGraphics(1876): framebuffer: (5, 6, 5, 0)
09-10 22:42:11.509: I/AndroidGraphics(1876): depthbuffer: (16)
09-10 22:42:11.509: I/AndroidGraphics(1876): stencilbuffer: (0)
09-10 22:42:11.509: I/AndroidGraphics(1876): samples: (0)
09-10 22:42:11.509: I/AndroidGraphics(1876): coverage sampling: (false)
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed meshes/app: { }
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed textures/app: { }
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed cubemap/app: { }
09-10 22:42:11.528: I/AndroidGraphics(1876): Managed shaders/app: { }
09-10 22:42:11.528: I/AndroidGraphics(1876): Managed buffers/app: { }
09-10 22:42:12.611: I/art(1876): Background partial concurrent mark sweep GC freed 236(29KB) AllocSpace objects, 1(93KB) LOS objects, 35% free, 932KB/1444KB, paused 33.449ms total 54.689ms
09-10 22:42:12.611: I/art(1876): --------- beginning of crash
09-10 22:42:12.621: E/AndroidRuntime(1876): FATAL EXCEPTION: GLThread 117
09-10 22:42:12.621: E/AndroidRuntime(1876): Process: com.mainTest.android, PID: 1876
09-10 22:42:12.621: E/AndroidRuntime(1876): com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:74)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.mainTest.AndroidTester.create(AndroidTester.java:30)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
09-10 22:42:12.621: E/AndroidRuntime(1876): Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.fromJson(Json.java:683)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
09-10 22:42:12.621: E/AndroidRuntime(1876):     ... 5 more
09-10 22:42:12.621: E/AndroidRuntime(1876): Caused by: com.badlogic.gdx.utils.SerializationException: Font file not found: default.fnt
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:446)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:437)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:873)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:404)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:834)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:425)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:414)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:410)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:873)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:404)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.fromJson(Json.java:681)
09-10 22:42:12.621: E/AndroidRuntime(1876):     ... 6 more
09-10 22:42:13.031: I/AndroidInput(1876): sensor listener tear down
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed meshes/app: { }
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed textures/app: { }
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed cubemap/app: { }
09-10 22:42:13.032: I/AndroidGraphics(1876): Managed shaders/app: { }
09-10 22:42:13.032: I/AndroidGraphics(1876): Managed buffers/app: { }

Solution

  • I solved the problem. According to the stacktrace, the file default.fnt was not found, throwing a SerializationException.

    Apparantly the files default.fnt and default.png must be in the Assets folder as well to launch on Android, but are not needed when launched from desktop. (Correct me if I'm wrong). After adding the files the skin loads succesfully and the application no longer crashes.

    I am marking this as solved for other people with the same problem, as well with a link to the files: default.fnt & default.png.