1

I am trying to implement Accelerometer in my game using Andengine and i also add andenginephysicsbox2dextension.jar

private PhysicsWorld mPhysicsWorld;

//--OnLoadScene()

this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

When i implement this line i got error and not able to run.

How to fix this error?

Logcat Errors:

07-27 13:57:21.125: ERROR/AndroidRuntime(1006): FATAL EXCEPTION: main
07-27 13:57:21.125: ERROR/AndroidRuntime(1006): java.lang.ExceptionInInitializerError
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at Org.Demo.PixelPerfectTest.onLoadScene(PixelPerfectTest.java:223)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:158)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:82)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2152)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.view.View.dispatchWindowFocusChanged(View.java:4691)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:752)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.view.ViewRoot.handleMessage(ViewRoot.java:2102)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.os.Looper.loop(Looper.java:132)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at android.app.ActivityThread.main(ActivityThread.java:4025)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at java.lang.reflect.Method.invokeNative(Native Method)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at java.lang.reflect.Method.invoke(Method.java:491)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at dalvik.system.NativeStart.main(Native Method)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension: findLibrary returned null
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at java.lang.Runtime.loadLibrary(Runtime.java:425)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at java.lang.System.loadLibrary(System.java:554)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     at org.anddev.andengine.extension.physics.box2d.PhysicsWorld.<clinit>(PhysicsWorld.java:30)
07-27 13:57:21.125: ERROR/AndroidRuntime(1006):     ... 15 more
mdelolmo
  • 6,417
  • 3
  • 40
  • 58
JohnRaja
  • 2,377
  • 6
  • 26
  • 47

4 Answers4

4

You have to include the .so files in libs AND add the .jar files via Project Properties. There are two versions of the two .so files (arneabu and armeabi-v7a) ... I don't know which is more current. Put them in libs and make sure you refresh your build path.

Then, if you haven't already done so, make sure you include the relevant .jar files by pulling up Project Properties in Eclipse. Then, without loading Eclipse (I'd have to kill this browser to avoid bogging this POS laptop down too much), I'm 99% sure it's under Build Path, you'll see an option to "Add External JARs". Select that, and add the necessary jar files.

Apparently, based on a thread I read, forgetting the .so libs is a somewhat common mistake (one I made, too!).

Now, if your app is a live wallpaper, expect problems with any AndEngine physics. I've read a LOT of posts about people having problems, looking for a bug fix, and so on.

I have an open question in the AndEngine forums now about that very issue. I can't get any touch events or the accelerometer to work AT ALL in my physics and physics-based (physics/chemistry: Buckyballs (buckminsterfullerenes), and physics code for AndEngine) LWP app. I've basically run into a brick wall that makes it pointless to move forward until (and IF) I get a response to the latest update I added....

Hope this helps....

Later,
   --jim

GTbrewer
  • 165
  • 1
  • 9
2

Note this line:

07-27 13:57:21.125: ERROR/AndroidRuntime(1006): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension: findLibrary returned null

Verify your Build Path settings, maybe you're ignoring a required library/extensions? By the information you give, and considering I haven't used that library. Maybe you need to add the Physics Box2D Extension to the Build Path.

Regards.

mdelolmo
  • 6,417
  • 3
  • 40
  • 58
0

As your project is ignoring .so files. you can follow my answer here https://stackoverflow.com/a/34068202/2026280

or

Its very simple. Follow this simple steps

1) Create a new folder called "lib" inside the libs folder of the main app.

2) Copy all the folders ie.armabi , armabi-v7a etc from andEnginePhysicsBox2DExtension/libs folder, and paste in in the previously created "lib" folder in main app.

3) Now compress the "lib" folder as "lib.zip" and rename it to "lib.jar". this changes the zip extension to jar.

4) Finally add a line -- compile files('lib.jar') under dependencies{} in Build.gradle file of your main app.

5) Clean and build the project.

Community
  • 1
  • 1
Sandeep R
  • 2,284
  • 3
  • 25
  • 51
0

GTBrewer. Simply build the native libs in the physicsbox2d project. then cp -r ./libs from the physics project to the live wallpaper project. refresh, project->clean then build. viola!

Andro Selva
  • 53,910
  • 52
  • 193
  • 240