Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PolygonShape Native Method not found using new libgdx gradle project

I have a LibGDX project in android studio that uses gradle. It worked well until this morning but due to LibGDX changes now the box2d extension doesn't work properly.

I think i've already done the right imports like so:

  • build.gradle (root of the project)
project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile fileTree (dir:'../libs', include:['*.jar'])
    }
}


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

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        compile fileTree (dir:'../libs', include:['*.jar'])
    }
}

(rest of build.gradle omitted for simplicity)

However when I try to use PolygonShape I get the following error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method) at com.badlogic.gdx.physics.box2d.PolygonShape.(PolygonShape.java:29) at com.marclabsoftware.app.utilities.BodyEditorLoader.(BodyEditorLoader.java:34) at com.marclabsoftware.app.utilities.Utilities.init(Utilities.java:81) at com.marclabsoftware.app.App.create(App.java:50) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

Is there a way to fix this error? Thanks for any reply

like image 255
LaboDJ Avatar asked Apr 18 '14 21:04

LaboDJ


1 Answers

The problem is that you're trying to load PolygonShapes before the native library for Box2D has been loaded. As explained here, the Box2D native libraries are loaded in a static initializer of the World class.

I'm not sure if this is intended behavior, but it seems like an edge case that was missed when refactoring the Box2D code into an extension.

You can work around this either by creating a World, or by loading the Box2D native library, before loading your polygons/bodies/whatever.

I'm not exactly sure how to load native libraries, but a simple new World(args) should do just fine.

like image 87
Nora Powers Avatar answered Sep 27 '22 20:09

Nora Powers