【问题标题】:libgdx SpriteBatch UnsatisfiedLinkError desktoplibgdx SpriteBatch UnsatisfiedLinkError 桌面
【发布时间】:2019-06-22 00:55:35
【问题描述】:

当我尝试运行它的桌面独立版本时,我在 LibGdx 项目中遇到 UnsatisfiedLinkError。请注意,如果我只是直接运行桌面版本而不为它构建独立 jar,则不会发生此问题,前提是我先构建桌面 jar,然后尝试运行它。有趣的是,总体而言,直接运行桌面版本要容易得多,在我找到一大堆 jar 文件并手动添加它们之前,我什至还没有接近运行独立的桌面 jar到 LibGdx 项目。

我在 Windows 10 x64 上使用 Android Studio 3.3、gradle 4.10 和 Java 1.8.0_201,并使用“gradle”命令将我的 LibGdx 应用程序的一个版本部署到桌面:

gradle desktop:dist 来自 ProjectRoot。

然后在运行由它创建的 jar 文件时,通过在 ProjectRoot 的命令行中键入:

cd desktop/build/libs,然后是java -jar desktop-1.0.jar

这样做后,我会收到 UnsatisfiedLinkError error

我尝试将 jar 文件复制到 Linux 并在那里进行测试,但我得到了同样的错误。

我进行了一些搜索,发现a suggestion 可能是对new SpriteBatch() 的调用发生得太早了:

就像在核心模块中的create() 函数之前一样,但这不是问题,因为new SpriteBatch() 调用从来没有早于此。

该链接中使用LibGdx Setup Generator 的建议也对我没有帮助,因为我已经使用LibGdx Setup Generator GUI 工具创建了同一个项目,但我仍然遇到这个问题。

尽管从程序的输出中我注意到,它在 new SpriteBatch() 调用上抛出了 UnsatifisedLinkError 异常,因为该链接确实引用了该链接,但它是从 create() 函数调用的,并且不早于此。

我做了一个实验,发现如果我完全删除了 new SpriteBatch() 调用以及依赖于该调用的所有其他代码,例如创建纹理,并使用精灵批处理来绘制该纹理。我发现通过这样做,程序运行时没有出现错误,当然我也无法那样绘制任何东西。

所以,然后我又做了一个实验,将 new SpriteBatch() 调用从 create 函数中移到 render() 函数中,如下所示,正如您将在代码中注意到的那样。我只是尝试在每次 render() 函数执行时创建 SpriteBatch()(如果尚未创建),并输出它抛出了多少次 UnsatisfiedLinkError exception

--------------MyGdxGame.java-------- -------------------

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;
    long numAttempts = 0;

    @Override
    public void create () {

    }

    @Override
    public void render () {

        if (batch == null) {
            try {
                batch = new SpriteBatch();
            } catch (UnsatisfiedLinkError error) {
                System.out.println("Failed create SpriteBatch attempt #" + numAttempts);
                ++numAttempts;
            }

            if (batch != null) {
                img = new Texture("badlogic.jpg");
            }
        }

        Gdx.gl.glClearColor(1, 1, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        //batch.begin();
        //batch.draw(img, img.getWidth(), 0);
        //batch.end();
    }

    @Override
    public void dispose () {
        //batch.dispose();
        //img.dispose();
    }
}

上面的代码最终创建了这个输出:

Failed create SpriteBatch attempt #0
Failed create SpriteBatch attempt #1
Failed create SpriteBatch attempt #2
Failed create SpriteBatch attempt #3
Failed create SpriteBatch attempt #4
Failed create SpriteBatch attempt #5
Failed create SpriteBatch attempt #6
Failed create SpriteBatch attempt #7
Failed create SpriteBatch attempt #8
Failed create SpriteBatch attempt #9
Failed create SpriteBatch attempt #10
Failed create SpriteBatch attempt #11
Failed create SpriteBatch attempt #12

如果我允许应用程序继续运行,它似乎会继续运行,说“失败的创建 SpriteBatch 尝试#...”。

如您所见,似乎无论发生多少渲染帧,new SpriteBatch() 都会抛出UnsatifiedLinkError 异常,所以这显然不是问题,因为我在程序中太早调用了new SpriteBatch() .

我还看到here 的另一个建议,我应该为桌面版本做这样的事情:

static {
    GdxNativesLoader.load();
}

在其他地方,我不记得在哪里,我看到了这个建议:

LwjglNativesLoader.load();

所以我尝试了这两种方法,但不是同时尝试,但都没有奏效,我将它们放在 DesktopLauncher 文件中,如下所示:

--------DesktopLauncher.java------------------------------------ -------

package com.mygdx.game.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl.LwjglNativesLoader;
import com.badlogic.gdx.utils.GdxNativesLoader;
import com.mygdx.game.MyGdxGame;

public class DesktopLauncher {

    static {
        //GdxNativesLoader.load(); // I tried with this line of code
        //LwjglNativesLoader.load(); // and separately with this line
    }

    public static void main (String[] arg) {

        //GdxNativesLoader.load(); // and separately with this line, here

        //LwjglNativesLoader.load(); // and separately with this line, here


        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();

        new LwjglApplication(new MyGdxGame(), config);
    }
}

这些都没有解决它。我还记得看到一些链接表明我的 gdx 本机 jar 和我的 gdx jar 可能不匹配,但我不确定如何检查,但我会显示我添加到 desktop/libs 的 jar 列表文件夹和我的gradle.build 文件:

--------jar 文件:-------------

core-1.0.jar
desktop-1.0.jar
gdx-1.9.9.jar
gdx-backend-lwjgl-1.9.9.jar
gdx-backend-lwjgl-natives.jar
gdx-natives.jar
gdx-openal.jar
gdx-platform-1.9.9.jar
jinput-2.0.5.jar
jinput-platform-2.0.5-natives-linux.jar
jinput-platform-2.0.5-natives-osx.jar
jinput-platform-2.0.5-natives-windows.jar
jutils-1.0.0.jar
lwjgl-2.9.0.jar
lwjgl-2.9.2.jar
lwjgl-3.2.1.jar
lwjgl-openal-3.2.1.jar
lwjgl-platform-2.9.2-natives-linux.jar
lwjgl-platform-2.9.2-natives-osx.jar
lwjgl-platform-2.9.2-natives-windows.jar

这是我的 build.gradle 文件的一部分,其中包含我需要手动添加的 jar 文件,甚至可以让我的 LibGdx 版本的桌面独立版本完全运行:

----我的 build.gradle 文件的一部分------------

project(":desktop") {

    apply plugin: "java"

    dependencies {
        implementation project(":core")

        // ... a bunch of irrelevant implementation lines here

        compile files("libs/gdx-1.9.9.jar")
        compile files("libs/gdx-backend-lwjgl-1.9.9.jar")
        compile files("libs/lwjgl-2.9.0.jar")
        compile files("libs/core-1.0.jar")
        compile files("libs/desktop-1.0.jar")
        compile files("libs/gdx-natives.jar")

        // Noticed I commented these ones out
        // compile files("libs/gdx-backend-lwjgl-natives.jar")
        //compile files("libs/gdx-platform-1.9.9.jar")
        //compile files("libs/lwjgl-3.2.1.jar")

        compile files("libs/lwjgl-openal-3.2.1.jar")
        compile files("libs/jinput-2.0.5.jar")

        // Noticed I also commented out these
        //compile files("libs/jinput-platform-2.0.5-natives-linux.jar")
        //compile files("libs/jinput-platform-2.0.5-natives-osx.jar")
        //compile files("libs/jinput-platform-2.0.5-natives-windows.jar")
        //compile files("libs/jinput-1.0.0.jar")

        compile files("libs/jutils-1.0.0.jar")
        compile 'org.lwjgl.lwjgl:lwjgl:2.9.2'
        compile files("libs/lwjgl-2.9.2.jar")
        compile files("libs/lwjgl-platform-2.9.2-natives-linux.jar")
        compile files("libs/lwjgl-platform-2.9.2-natives-osx.jar")
        compile files("libs/lwjgl-platform-2.9.2-natives-windows.jar")
    }
}

如果您想知道,我总是确保我的 core-1.0.jar 和 desktop-1.0.jar 是最新的,方法是构建我的桌面版本,将这些 jar 复制到 desktop/libs 文件夹中,然后重建它,所以这不是部分问题。

无论如何,经过所有这些研究和所有这些实验,我还没有找到问题的原因和解决方案。任何帮助将不胜感激,非常感谢!

后期编辑:

我的类路径是这样的:

0: C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar
1: C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar
2: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar
3: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar
4: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar
5: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar
6: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar
7: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar
8: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar
9: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar
10: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar
11: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar
12: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar
13: C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar
14: C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar
15: C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar
16: C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar
17: C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar
18: C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar
19: C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar
20: C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar
21: C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar
22: C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar
23: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\build\classes\java\main
24: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\build\classes\kotlin\main
25: C:\Users\me\AndroidStudioProjects\TestHtml\core\build\classes\java\main
26: C:\Users\me\.gradle\caches\modules-2\files-2.1\de.tomgrill.gdxdialogs\gdx-dialogs-core\1.2.5\c55ef7e82d013ea7d99a66dcbdc24cfa7127337e\gdx-dialogs-core-1.2.5.jar
27: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.box2dlights\box2dlights\1.4\3d77ad5b4164fb32fc67e2446e35911bb0aaf0bd\box2dlights-1.4.jar
28: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.dermetfan.libgdx-utils\libgdx-utils-box2d\0.13.4\918d79a20ea3c898cdb3611782c5b2bfa6ec575b\libgdx-utils-box2d-0.13.4.jar
29: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-box2d\1.9.9\e9a43c50fbe4f1e26dd0af5d2e78d125549e7f6b\gdx-box2d-1.9.9.jar
30: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.ashley\ashley\1.7.0\a7c4083c0a42027a3c03ba7ccecef6cbe1c5f0a4\ashley-1.7.0.jar
31: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-ai\1.8.0\ec30677d8ab1a8b8aa4b853c5f4e4b1361f50bf5\gdx-ai-1.8.0.jar
32: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-controllers\1.9.9\55b69a040e076b17d01a5057f9cb2ce338a3331a\gdx-controllers-1.9.9.jar
33: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.github.czyzby\gdx-lml-vis\1.9.1.9.6\951c197ebe8c9644bd555722c449fa4cfda527fb\gdx-lml-vis-1.9.1.9.6.jar
34: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.kotcrab.vis\vis-ui\1.3.0\639741faa66a560197ee06a9412949402c831796\vis-ui-1.3.0.jar
35: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.dermetfan.libgdx-utils\libgdx-utils\0.13.4\27affad2873d1c9c366a2290fc51f3927f3a5f83\libgdx-utils-0.13.4.jar
36: C:\Users\me\.gradle\caches\modules-2\files-2.1\de.tomgrill.gdxfacebook\gdx-facebook-core\1.4.1\1b5d4948b033a4b9a8f360d0fa76c49e6e17baec\gdx-facebook-core-1.4.1.jar
37: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx\1.9.9\bf26f2f816b3cfe37ac6e66615391c30714b7030\gdx-1.9.9.jar
38: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.esotericsoftware.spine\spine-libgdx\3.6.53.1\281f862762c15a8f8a79443a57526f4238b52b8e\spine-libgdx-3.6.53.1.jar
39: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.github.czyzby\gdx-lml\1.9.1.9.6\2590018dd6fc37566e3998db2cc2ecce0155c3b4\gdx-lml-1.9.1.9.6.jar
40: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.github.czyzby\gdx-kiwi\1.9.1.9.6\c00391b240ccf1212f3acd2095b6df489d4ff281\gdx-kiwi-1.9.1.9.6.jar
41: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-tools\1.9.9\55228989f0479dd4bbe487766eda15e5d512c51e\gdx-tools-1.9.9.jar
42: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-backend-lwjgl\1.9.9\ca8911cb94c0bfeb59f99e46ca9b92440958fb0e\gdx-backend-lwjgl-1.9.9.jar
43: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.lwjgl.lwjgl\lwjgl_util\2.9.2\4b9e37300a87799856e0bd15ed81663cdb6b0947\lwjgl_util-2.9.2.jar
44: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.lwjgl.lwjgl\lwjgl\2.9.2\a9d80fe5935c7a9149f6584d9777cfd471f65489\lwjgl-2.9.2.jar
45: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-platform\1.9.9\7e644cfafdb436b13b24ac7993ffab17f306b64d\gdx-platform-1.9.9-natives-desktop.jar
46: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-box2d-platform\1.9.9\72b2916f45f3f948896eda931cd597f7e698340f\gdx-box2d-platform-1.9.9-natives-desktop.jar
47: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-controllers-desktop\1.9.9\d4b8b62f077382db145e7a94a27a994b68ce6ee\gdx-controllers-desktop-1.9.9.jar
48: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-controllers-platform\1.9.9\26b8735060fdfd7dc6529cf5085fa57144a349d9\gdx-controllers-platform-1.9.9-natives-desktop.jar
49: C:\Users\me\.gradle\caches\modules-2\files-2.1\de.tomgrill.gdxfacebook\gdx-facebook-desktop\1.4.1\709e9a585082d7b875540d33ee3a4f4787ea74c3\gdx-facebook-desktop-1.4.1.jar
50: C:\Users\me\.gradle\caches\modules-2\files-2.1\de.tomgrill.gdxdialogs\gdx-dialogs-desktop\1.2.5\233048054a845d7a59d86c54e9d74f95749f74b5\gdx-dialogs-desktop-1.2.5.jar
51: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.20\b1f3cb184c4ce4139741454df2f8fca5320f822d\kotlin-stdlib-jdk8-1.3.20.jar
52: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.lwjgl.lwjgl\lwjgl-platform\2.9.2\510c7d317f5e9e700b9cfaac5fd38bdebf0702e0\lwjgl-platform-2.9.2-natives-windows.jar
53: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.lwjgl.lwjgl\lwjgl-platform\2.9.2\d276cdf61fe2b516c7b7f4aa1b8dea91dbdc8d56\lwjgl-platform-2.9.2-natives-linux.jar
54: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.lwjgl.lwjgl\lwjgl-platform\2.9.2\d55b46b40b40249d627a83a7f7f22649709d70c3\lwjgl-platform-2.9.2-natives-osx.jar
55: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.java.jinput\jinput\2.0.5\39c7796b469a600f72380316f6b1f11db6c2c7c4\jinput-2.0.5.jar
56: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-backend-headless\1.9.9\657d1d232f274162eb8fd600a137b2221f2fc9c\gdx-backend-headless-1.9.9.jar
57: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-freetype\1.9.9\d947872087863b654d9a0e27a8cb10a29d6fd3d6\gdx-freetype-1.9.9.jar
58: C:\Users\me\.gradle\caches\modules-2\files-2.1\com.badlogicgames.jlayer\jlayer\1.0.1-gdx\7cca83cec5c1b2f011362f4d85aabd71a73b049d\jlayer-1.0.1-gdx.jar
59: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jcraft\jorbis\0.0.17\8872d22b293e8f5d7d56ff92be966e6dc28ebdc6\jorbis-0.0.17.jar
60: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.20\aa17d6fd473ce53061a7b2b9d2ae96f547cae93d\kotlin-stdlib-jdk7-1.3.20.jar
61: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.20\eb2a232734e09fcd1b958a5c7520a93c6de38b32\kotlin-stdlib-1.3.20.jar
62: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.java.jutils\jutils\1.0.0\e12fe1fda814bd348c1579329c86943d2cd3c6a6\jutils-1.0.0.jar
63: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.java.jinput\jinput-platform\2.0.5\7ff832a6eb9ab6a767f1ade2b548092d0fa64795\jinput-platform-2.0.5-natives-linux.jar
64: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.java.jinput\jinput-platform\2.0.5\385ee093e01f587f30ee1c8a2ee7d408fd732e16\jinput-platform-2.0.5-natives-windows.jar
65: C:\Users\me\.gradle\caches\modules-2\files-2.1\net.java.jinput\jinput-platform\2.0.5\53f9c919f34d2ca9de8c51fc4e1e8282029a9232\jinput-platform-2.0.5-natives-osx.jar
66: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.20\7d7934e26ce34da1a0a8d00e38038d7cf3375e89\kotlin-stdlib-common-1.3.20.jar
67: C:\Users\me\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar
68: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\core-1.0.jar
69: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\gdx-natives.jar
70: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\lwjgl-3.2.1.jar
71: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\lwjgl-natives-linux.jar
72: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\lwjgl-natives-macos.jar
73: C:\Users\me\AndroidStudioProjects\TestHtml\desktop\libs\lwjgl-natives-windows.jar
74: C:\Program Files\Android\Android Studio\lib\idea_rt.jar

更新:

我在 build.gradle 中的完整桌面模块:

   project(":desktop") {
    //apply plugin: "application"
    //mainClassName = "DesktopLauncher"
    apply plugin: "java"


    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
        implementation "de.tomgrill.gdxfacebook:gdx-facebook-desktop:1.4.1"
        implementation "de.tomgrill.gdxdialogs:gdx-dialogs-desktop:1.2.5"

        //implementation "com.badlogicgames.gdx:gdx:1.9.9"
        compile files("libs/gdx-1.9.9.jar")
        compile files("libs/gdx-backend-lwjgl-1.9.9.jar")
        //compile files("libs/lwjgl-2.9.0.jar")
        compile files("libs/core-1.0.jar")
        //compile files("libs/desktop-1.0.jar")
        compile files("libs/gdx-natives.jar")
        // compile files("libs/gdx-backend-lwjgl-natives.jar")
        //compile files("libs/gdx-platform-1.9.9.jar")
        //compile files("libs/lwjgl-3.2.1.jar")

        /*
        compile files("libs/lwjgl-openal-3.2.1.jar")
        compile files("libs/jinput-2.0.5.jar")
        compile files("libs/jinput-platform-2.0.5-natives-linux.jar")
        compile files("libs/jinput-platform-2.0.5-natives-osx.jar")
        compile files("libs/jinput-platform-2.0.5-natives-windows.jar")
        */

        //compile files("libs/jinput-1.0.0.jar")

        compile files("libs/jutils-1.0.0.jar")


        compile 'org.lwjgl.lwjgl:lwjgl:2.9.2'
        compile files("libs/lwjgl-3.2.1.jar")

        compile files("libs/lwjgl-platform-2.9.2-natives-linux.jar")
        compile files("libs/lwjgl-platform-2.9.2-natives-osx.jar")
        compile files("libs/lwjgl-platform-2.9.2-natives-windows.jar")

        compile files("libs/lwjgl-natives-linux.jar")
        compile files("libs/lwjgl-natives-macos.jar")
        compile files("libs/lwjgl-natives-windows.jar")
    }
}

【问题讨论】:

  • 我认为这个问题与本机 jar 或 lwjgl jar 有关,请记住,这个问题仍然有 50 分的赏金给谁能为我找到解决方案。
  • 在赏金 5 天后还没有帮助 - 好吧,我现在意识到该错误实际上是运行时链接器错误,但我还没有想出如何解决它,我尝试用 gradle 中的本机 jar 替换“编译”,这只是给了我这个错误:在 org.gradle.api.internal.artifacts.dsl 类型的对象上找不到参数 [文件集合] 的方法 natives()。依赖项.DefaultDependencyHandler。仍在寻求帮助
  • 即使赏金到期也没有答案
  • 我之前的回答不能解决您的问题。这并没有错,但我没有考虑到 libgdx 应该已经打包原生的事实。
  • 虽然在静态块中添加GdxNativesLoader.load(); 不起作用,但我相信问题肯定出在您的类路径上。没有任何代码。

标签: gradle libgdx desktop-application unsatisfiedlinkerror spritebatch


【解决方案1】:

请修改build.gradle内容如下,再次同步gradle并检查一次。

project(":desktop") {
    apply plugin: "java"


    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:1.9.9"
        implementation "com.badlogicgames.gdx:gdx-platform:1.9.9:natives-desktop"
        implementation "com.badlogicgames.gdx:gdx-box2d-platform:1.9.9:natives-desktop"

    }
}

我认为您正在使用不需要的额外不必要的库。

我在 bitbucket 上添加了一个工作示例项目,您可以从中克隆它并与您的比较

git clone https://zumbarlalsaindane@bitbucket.org/zumbarlalsaindane/libgdx-test.git

在运行应用程序之前,请执行以下步骤:

   Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab
   => Working Directory => Others then browse to yourproject-android/assets/ 
   and click Apply => Run

【讨论】:

  • 我的 build.gradle 桌面模块中已经有所有 3 个依赖项,只有 1.9.9 而不是 1.9.9,我有 $gdxVersion,我将更新我的问题以在 build.gradle 中显示我的整个桌面模块,如果可以的话,请检查一下。
  • 我尝试在 build.gradle 中从我的桌面模块中删除所有其他内容,然后将你拥有的内容放入其中,但这让我回到了我第一次尝试使桌面可分发时遇到的一个旧错误,即:错误:发生 JNI 错误,请检查您的安装并重试 线程“main”中的异常 java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener ,我已经修复了。
  • 您的回答没有直接帮助,但它让我找到了解决方案。虽然您的版本在运行由命令gradle desktop:dist 创建的独立桌面 jar 时有效,但即使通过将我的 gdxVersion 从 1.9.9 更改为 1.9.8,我的 roboVMVersion 从2.3.5 到 2.3.3 并删除它不喜欢的 google(),因为我也有一个 html 模块,所以我寻找其他差异,我发现你在项目结构中使用 gradle 版本 2.14.1 & I正在使用 4.10.1,所以我改变了它,但后来它开始了......
  • ...抱怨其他 gradle 设置我不得不适应我拥有的各种其他平台,例如 html、android 和 ios (roboVM),所以我决定只用桌面创建一个项目使用 libgdx 工具,现在一个 java 独立工作,这不是因为版本的差异,只是其他平台的一些冲突设置,所以我的解决方案是简单地将同一个项目的两个副本并排,一个用于桌面,1 个用于所有其他平台,只需复制相同的代码(如果结果证明任何其他平台的 gradle 设置,甚至超过 2 个副本......
  • ...平台最终会相互冲突)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-13
  • 2015-08-03
  • 1970-01-01
  • 2014-10-28
  • 2011-11-24
  • 1970-01-01
相关资源
最近更新 更多