如何修复“无法加载目标的共享库‘libgdx64.so’:Linux,64位”

twi*_*wiz 5 java libgdx

我正在尝试使用无头 LibGDX 进行单元测试,但是当我运行测试时出现此错误:

无法加载目标的共享库“libgdx64.so”:Linux,64位

在这里读到我需要添加gdx-natives.jar. 这是正确的吗?在哪里可以找到该文件?

另外,我应该在项目中的哪里添加该文件?

twi*_*wiz 5

我在这个 BitBucket repo上找到了答案。自述文件很好地解释了如何使用 Gradle 实现这一点。

基本上,您只需从该存储库添加GdxTestRunner.java,然后将 a 添加@RunWith到每个测试文件中:

@RunWith(GdxTestRunner.class)
public class MyClassTest {
    ...
}
Run Code Online (Sandbox Code Playgroud)

然后在根级别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"
Run Code Online (Sandbox Code Playgroud)

显然,仅当您使用这些库时才需要box2d和依赖项。bullet


在 BitBucket 存储库自述文件中,该示例包括

testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
Run Code Online (Sandbox Code Playgroud)

compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
Run Code Online (Sandbox Code Playgroud)

我认为没有必要将其包含在 for 中compile,并且如果我正确理解 Gradle 的工作原理,它实际上会减慢您的构建速度。