Android Studio / LibGdx/ Fatal error

1.1k views Asked by At

I am trying to develop my first Android game using LibGdx and Tween Engine for the Animations. However, always if I try to run it on my phone I get the following error:

06-14 17:00:43.894  31239-31270/com.joelbrun.jetskirider.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 4726
Process: com.joelbrun.jetskirider.android, PID: 31239
java.lang.NoClassDefFoundError: Failed resolution of: Laurelienribon/tweenengine/TweenManager;
        at com.joelbrun.jetskirider.screens.Splash.show(Splash.java:26)
        at com.badlogic.gdx.Game.setScreen(Game.java:61)
        at com.joelbrun.jetskirider.JetskiRider.create(JetskiRider.java:10)
        at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "aurelienribon.tweenengine.TweenManager" on path: DexPathList[[zip file "/data/app/com.joelbrun.jetskirider.android-2/base.apk"],nativeLibraryDirectories=[/data/app/com.joelbrun.jetskirider.android-2/lib/arm, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.joelbrun.jetskirider.screens.Splash.show(Splash.java:26)
            at com.badlogic.gdx.Game.setScreen(Game.java:61)
            at com.joelbrun.jetskirider.JetskiRider.create(JetskiRider.java:10)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
Suppressed: java.lang.ClassNotFoundException: aurelienribon.tweenengine.TweenManager
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 7 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Classes: Main Class (JetskiRider)

package com.joelbrun.jetskirider;

import com.badlogic.gdx.Game;
import com.joelbrun.jetskirider.screens.Splash;

public class JetskiRider extends Game {

    @Override
    public void create () {
        setScreen(new Splash());
    }

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

    @Override
    public void resume() {
        super.resume();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void render () {
        super.render();
    }
}

Splash (Splashscreen)

package com.joelbrun.jetskirider.screens;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.joelbrun.jetskirider.tween.SpriteAccessor;

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager;

public class Splash implements Screen {

    private SpriteBatch batch;
    private Sprite splash;
    private TweenManager tweenManager;

    @Override
    public void show() {
        batch = new SpriteBatch();
        tweenManager = new TweenManager();
        Tween.registerAccessor(Sprite.class, new SpriteAccessor());

        Texture splashTexture = new Texture("splash.png");
        splash = new Sprite(splashTexture);
        splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
        Tween.to(splash, SpriteAccessor.ALPHA, 2).target(1).repeatYoyo(1, 2).setCallback(new TweenCallback() {
            @Override
            public void onEvent(int type, BaseTween<?> source) {
                ((Game)Gdx.app.getApplicationListener()).setScreen(new MainMenu());
            }
        }).start(tweenManager);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0,0,0,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        tweenManager.update(delta);

        batch.begin();
        splash.draw(batch);
        batch.end();
    }

    @Override
    public void resize(int width, int height) {
        resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        batch.dispose();
        splash.getTexture().dispose();
    }
}

MainMenu (Main Menu after Splash screen; not finished yet)

package com.joelbrun.jetskirider.screens;

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

import javafx.stage.Stage;

public class MainMenu implements Screen {

    private Stage stage;
    private Table table;
    private Label highscore;

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {

    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}

Sprite Accessor (For Accessor for Tween Engine)

package com.joelbrun.jetskirider.tween;

import com.badlogic.gdx.graphics.g2d.Sprite;
import aurelienribon.tweenengine.TweenAccessor;

public class SpriteAccessor implements TweenAccessor<Sprite> {

    public static final int ALPHA = 0;

    @Override
    public int getValues(Sprite target, int tweenType, float[] returnValues) {
        switch (tweenType) {
            case ALPHA:
                returnValues[0] = target.getColor().a;
                return 1;
            default:
                assert false;
                return -1;
        }
    }

    @Override
    public void setValues(Sprite target, int tweenType, float[] newValues) {
        switch (tweenType){
            case ALPHA:
                target.setColor(target.getColor().r, target.getColor().g, target.getColor().b, newValues[0]);
            default:
                assert false;
        }
    }
}
1

There are 1 answers

1
p.streef On BEST ANSWER

edit your build.gradle to load the tween lib from repository (it could be there is a newer version, my own project works with this):

project(":core") {
apply plugin: "java"

dependencies {
    compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    compile "aurelienribon:tweenengine:6.3.3"
    compile "aurelienribon:tweenengine:6.3.3:sources"
}
}

and you might need to remove the tween jar from the libs folder