AndEnginePhysicsBox2D NoClassDefFoundError

429 Views Asked by At

I am gettin an error : java.lang.NoClassDefFoundError org.andengine.extension.physics.box2D.PhysicsWorld. It seem could not find the PhysicsWorld class. Everything else seems ok with my project. Everything is green and checked on Properioes > Android , >BuildPath , > Libraries Test device:Samsung Galaxy S3 (Android JellyBean 4.3)


Ok here is my code :

package com.andengine.test;

import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.WakeLockOptions;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.extension.physics.box2d.PhysicsConnector;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.adt.color.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import android.graphics.Point;
import android.hardware.SensorManager;
import android.view.Display;

public class SimpleGame extends BaseGameActivity {

private EngineOptions engineOptions;
private Camera mCamera;
private Scene mScene;
int cameraWidth, cameraHeight;
public Point size;
BitmapTextureAtlas playerTexture;
ITextureRegion playerTextureRegion;
PhysicsWorld physicsWorld;

@Override
public EngineOptions onCreateEngineOptions() {
    final Display display = getWindowManager().getDefaultDisplay();
    size = new Point();
    display.getSize(size);
    cameraWidth = size.x;
    cameraHeight = size.y;
    mCamera = new Camera(0, 0, cameraWidth, cameraHeight);
    engineOptions = new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
                    cameraWidth, cameraHeight), mCamera);
    engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    return engineOptions;
}

@Override
public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback) {
    loadGfx();
    pOnCreateResourcesCallback.onCreateResourcesFinished();
}

private void loadGfx() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    playerTexture = new BitmapTextureAtlas(getTextureManager(), 512, 512);
    playerTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(playerTexture, this, "ghost1.png", 0, 0);
    playerTexture.load();
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) {
    mScene = new Scene();
    physicsWorld = new PhysicsWorld(new Vector2(0,
            SensorManager.GRAVITY_EARTH), false);
    mScene.registerUpdateHandler(physicsWorld);
    mScene.setBackground(new Background(0, 125, 58));
    createWalls();
    pOnCreateSceneCallback.onCreateSceneFinished(mScene);
}

private void createWalls() {
    FixtureDef WALL_FIX = PhysicsFactory.createFixtureDef(0.0f, 0.0f, 0.0f);
    Rectangle ground = new Rectangle(0, cameraHeight - 15, cameraWidth, 15,
            mEngine.getVertexBufferObjectManager());
    ground.setColor(Color.BLACK);
    PhysicsFactory.createBoxBody(physicsWorld, ground,
            BodyDef.BodyType.StaticBody, WALL_FIX);
    mScene.attachChild(ground);
}

@Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback) {
    Sprite ghost1 = new Sprite(cameraWidth / 2, cameraHeight / 2,
            playerTextureRegion, mEngine.getVertexBufferObjectManager());
    FixtureDef ghost_FixtureDef = PhysicsFactory.createFixtureDef(10.0f,
            1.0f, 0.0f);
    Body body = PhysicsFactory.createCircleBody(physicsWorld, ghost1,
            BodyDef.BodyType.DynamicBody, ghost_FixtureDef);
    mScene.attachChild(ghost1);
    physicsWorld.registerPhysicsConnector(new PhysicsConnector(ghost1,
            body, true, false));
    pOnPopulateSceneCallback.onPopulateSceneFinished();
  }
}

and Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andengine.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name="SimpleGame" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>![enter image description here][1]

    11-20 21:55:51.070: E/AndEngine(12209): SimpleGame.onCreateScene failed. @(Thread: 'GLThread 15677')
11-20 21:55:51.070: E/AndEngine(12209): java.lang.NoClassDefFoundError: org.andengine.extension.physics.box2d.PhysicsWorld
11-20 21:55:51.070: E/AndEngine(12209):     at com.andengine.test.SimpleGame.onCreateScene(SimpleGame.java:72)
11-20 21:55:51.070: E/AndEngine(12209):     at org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:171)
11-20 21:55:51.070: E/AndEngine(12209):     at com.andengine.test.SimpleGame.onCreateResources(SimpleGame.java:58)
11-20 21:55:51.070: E/AndEngine(12209):     at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:183)
11-20 21:55:51.070: E/AndEngine(12209):     at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:112)
11-20 21:55:51.070: E/AndEngine(12209):     at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
11-20 21:55:51.070: E/AndEngine(12209):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
11-20 21:55:51.070: E/AndEngine(12209):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
1

There are 1 best solutions below

0
On BEST ANSWER

This is an issue with your Box2D Extension, make sure that :

  1. Make sure you use the Anchor Center version of the Box2D AndEngine Github, If that doesn't work :
  2. copy "armeabi"-"armeabi-v7a"-"x86" folders from "AndEnginePhysicsBox2DExtension" folder's "libs" folder to your game's "libs" folder