我正在尝试使用无头 LibGDX 进行单元测试,但是当我运行测试时出现此错误:
无法加载目标的共享库“libgdx64.so”:Linux,64位
我在here读到我需要添加
gdx-natives.jar
。这是正确的吗?我在哪里可以找到这个文件?
另外,我应该在项目中的哪个位置添加该文件?
我在这个 BitBucket 存储库上找到了答案。自述文件很好地解释了如何使用 Gradle 实现这一点。
这个 GitHub 存储库 对如何使用 Gradle 实现这一点有很好的解释。
基本上,您只需从该存储库添加 GdxTestRunner.java,然后向每个测试文件添加
@RunWith
:
@RunWith(GdxTestRunner.class)
public class MyClassTest {
...
}
然后在您的根级别
build.gradle
文件中,将类似的内容添加到您的 core
依赖项中:
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
显然,仅当您使用这些库时才需要
box2d
和 bullet
依赖项。
在 BitBucket 存储库自述文件中,示例包括两者
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
和
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
我认为没有必要将其包含在
compile
中,如果我正确理解 Gradle 的工作原理,它实际上会减慢你的构建速度。