4

I am trying to use the headless LibGDX for unit testing, but when I run the test I get this error:

Couldn't load shared library 'libgdx64.so' for target: Linux, 64-bit

I read here that I need to add gdx-natives.jar. Is this correct, and where can I find this file?

Also, where in my project should I add the file?

twiz
  • 9,041
  • 8
  • 52
  • 84
  • Here to download: http://libgdx.badlogicgames.com/releases/ Here for explanations: http://agmprojects.com/blog/setting-up-a-basic-libgdx-project – Guillaume Aug 29 '14 at 15:08
  • I guess I should have mention I am using IntelliJ IDEA and the LibGDX-setup-ui. I saw that tutorial before, but since it is based on a custom Eclipse project, I can't seem to get it to work in my project. – twiz Aug 29 '14 at 15:32
  • May be helpful : http://stackoverflow.com/questions/1051640/correct-way-to-add-lib-jar-to-an-intellij-idea-project – Guillaume Aug 29 '14 at 16:31
  • Am I right in thinking that the Maven support for libgdx is incomplete (or deprecated)? I'm getting this error when trying to run a small libgdx app that was built using Maven. – Mike Stoddart Feb 18 '20 at 20:48

1 Answers1

5

I found the answer on this BitBucket repo. The README gives a nice explanation of how to implement this using Gradle.

Basically, you just add GdxTestRunner.java from that repo, and then add a @RunWith to each of your test files:

@RunWith(GdxTestRunner.class)
public class MyClassTest {
    ...
}

Then in your root level build.gradle file, add something like this to your core dependencies:

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"

Obviously the box2d and bullet dependencies are only necessary if you are using those libraries.


On the BitBucket repo README, the example includes both

testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"

and

compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"

I don't think it is necessary to include this for compile, and if I correctly understand how Gradle works, it will actually slow down your build.

twiz
  • 9,041
  • 8
  • 52
  • 84