android 无法为目标加载共享库'gdx'

mzsu5hc0  于 2022-12-09  发布在  Android
关注(0)|答案(5)|浏览(174)

我遇到了与this question中相同的问题,但那里的答案不能解决我的问题。
我没有使用gdxsetup.jar创建项目,我只是包含了gdx.jar和gdx-backend-android.jar。我将www.example.com添加libgdx.so到了libs/x86中,但它仍然抛出异常。我应该如何解决这个问题?
日志目录:

02-16 11:59:45.604: E/AndroidRuntime(14788): FATAL EXCEPTION: main
02-16 11:59:45.604: E/AndroidRuntime(14788): java.lang.ExceptionInInitializerError
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.Class.newInstanceImpl(Native Method)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.Class.newInstance(Class.java:1130)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.os.Looper.loop(Looper.java:176)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at android.app.ActivityThread.main(ActivityThread.java:5419)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.reflect.Method.invoke(Method.java:525)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at dalvik.system.NativeStart.main(Native Method)
02-16 11:59:45.604: E/AndroidRuntime(14788): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx' for target: Linux, 32-bit
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:114)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:34)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.badlogic.gdx.backends.android.AndroidApplication.<clinit>(AndroidApplication.java:62)
02-16 11:59:45.604: E/AndroidRuntime(14788):    ... 15 more
02-16 11:59:45.604: E/AndroidRuntime(14788): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gdx from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.gamr-1.apk,libraryPath=/data/app-lib/com.example.gamr-1]: findLibrary returned null
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.Runtime.loadLibrary(Runtime.java:355)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at java.lang.System.loadLibrary(System.java:525)
02-16 11:59:45.604: E/AndroidRuntime(14788):    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:110)
02-16 11:59:45.604: E/AndroidRuntime(14788):    ... 17 more

如果有帮助的话,我运行的是32位Linux。

bt1cpqcv

bt1cpqcv1#

我遇到的问题是,由于某种原因,libgdx.so没有被复制到android项目的lib文件夹中的armeabiarmeabi-v7ax86文件夹中。
从libgdx发行版复制这些文件对我很有效。

w8ntj3qf

w8ntj3qf2#

我的问题是,我试图在一个共享库中制作我的GDX应用程序(又名,不是编译成APK的东西),但还没有完成设置所有的GDX-包括我的库中的东西。
于是我只好:

MyProject
-->MyMainApp
-->-->build.gradle <-- no updates required, doesn't do anything with GDX
-->MySharedLibraryWhereMyGameEngineIs
-->-->build.gradle <-- this is where the problem was

在共享库的build.gradle中,我没有包含sourceSets参数。
添加它修复了我的问题。GDX现在成功启动。

apply plugin: 'com.android.library'
android {
    ... config stuff ...

    sourceSets {                       // this wasn't here before
        main {                         // this wasn't here before
            jniLibs.srcDirs = ['libs'] // this wasn't here before
        }                              // this wasn't here before
        instrumentTest.setRoot('tests')// this wasn't here before
    }     

    ... a bunch of other config stuff ...
}
qv7cva1a

qv7cva1a3#

实际上,在我上传了第一次更新到我的应用程序(“十月兄弟”)后,我就遇到了同样的问题。虽然第一次发布在Play商店安装时运行得很好,但更新在启动后就崩溃了。检查Logcat,我确实遇到了这个问题。
为什么我的第一个版本没有问题,但没有更新的原因很简单:因为我只想修复一个小bug,所以我从GitHub checkout 了这个项目,只运行了一次桌面应用程序来验证修复,然后立即创建了签名的AppBundle。看起来我只需要在创建AppBundle之前运行至少一次“android”运行配置。或者更准确地说,是android模块的build.grade,它执行以下任务:

// android/build.gradle

...

// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives {
    doFirst {
        file("libs/armeabi/").mkdirs()
        file("libs/armeabi-v7a/").mkdirs()
        file("libs/arm64-v8a/").mkdirs()
        file("libs/x86_64/").mkdirs()
        file("libs/x86/").mkdirs()

        configurations.natives.files.each { jar ->
            def outputDir = null
            if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
            if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
            if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
            if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
            if(outputDir != null) {
                copy {
                    from zipTree(jar)
                    into outputDir
                    include "*.so"
                }
            }
        }
    }
}

我以为这个android/build.gradle是执行无论如何,一旦我点击建立〉建立捆绑包(s)/ APK(s)。但似乎不是这样。

xzabzqsa

xzabzqsa4#

我可以通过从copyAndroidNatives任务中删除armeabi本地机来修复此问题

// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives {
    doFirst {
        // file("libs/armeabi/").mkdirs()
        file("libs/armeabi-v7a/").mkdirs()
        file("libs/arm64-v8a/").mkdirs()
        file("libs/x86_64/").mkdirs()
        file("libs/x86/").mkdirs()

        configurations.natives.copy().files.each { jar ->
            def outputDir = null
            if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
            // if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
            if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
            if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
            if(outputDir != null) {
                copy {
                    from zipTree(jar)
                    into outputDir
                    include "*.so"
                }
            }
        }
    }
}
ou6hu8tu

ou6hu8tu5#

我发现这很简单:加了

static { System.loadLibrary("gdx");}

相关问题