Search code examples
javalibgdx

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


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?


Solution

  • I found the answer on this BitBucket repo. The README gives a nice explanation of how to implement this using Gradle. This GitHub repo has 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.