我在android studio中有一个使用gradle的LibGDX项目.它运作良好,直到今天早上,但由于LibGDX现在更改box2d扩展无法正常工作.
我想我已经完成了正确的进口:
build.gradle(项目的根)
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']) } }
(为简单起见省略了build.gradle的其余部分)
但是,当我尝试使用PolygonShape时,我收到以下错误:
线程"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)引起:java.lang.UnsatisfiedLinkError:com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape (本地方法)com.badlogic.gdx.physics.box2d.PolygonShape.(PolygonShape.java:29)位于com.marclabsoftware.app.utilities的com.marclabsoftware.app.utilities.BodyEditorLoader.(BodyEditorLoader.java:34). .Utilities.init(Utilities.java:81)位于com.badlogicoftware.app.App.cre.(App.java:50)com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)at at com.badlogic.gdx.backends.lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:114)
有没有办法解决这个错误?谢谢你的回复
问题是您在加载PolygonShapes
Box2D的本机库之前尝试加载.正如解释这里的Box2D的本地库被加载于静态初始化World
类.
我不确定这是否是预期的行为,但它似乎是将Box2D代码重构为扩展时遗漏的边缘情况.
您可以通过创建一个World
或通过加载Box2D本机库来解决此问题,然后再加载多边形/实体/任何内容.
我不确定如何加载本机库,但一个简单的new World(args)
应该做得很好.