无法为目标加载共享库’gdx’

我遇到的问题与此问题相同,但那里的答案并没有解决我的问题。

我没有通过gdxsetup.jar创建项目,我只包括gdx.jar和gdx-backend-android.jar。 我将libgdx.so添加到libs / x86,但它仍然会引发exception。 我该怎么解决这个问题?

logcat的:

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.(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。

我遇到的问题是由于某种原因libgdx.so没有复制到android项目的lib文件夹中的任何armeabiarmeabi-v7ax86文件夹。

从libgdx发行版中复制这些内容对我有用。

我的问题是我试图在共享库中创建我的GDX应用程序(也就是说,不是编译成APK的东西),但还没有在我的lib中设置所有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 ... } 

我发现这很简单:添加

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