Android JNA UnsatisfiedLinkError: Native library (com/sun/jna/xxx/libjnidispatch.so) not found

落花浮王杯 提交于 2019-12-03 00:22:17

问题


Hey I am trying to set up a android studio project with JNA and libvirt java bindings.

This is what the project structure looks like so far.

however the solution did not work for me

This is being tested not he emulator so far and the arm binaries have not been imported yet.

When trying to use Connect method in the libvirt java bindings I get this error.

There is a very similar post here

11-18 23:54:37.584 4182-4182/com.local.test E/AndroidRuntime: FATAL EXCEPTION: main
                                                           Process: com.local.test, PID: 4182
                                                           java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-x86/libjnidispatch.so) not found in resource path (.)
                                                               at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1039)
                                                               at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:999)
                                                               at com.sun.jna.Native.<clinit>(Native.java:191)
                                                               at com.sun.jna.Native.loadLibrary(Native.java:625)
                                                               at org.libvirt.jna.Libvirt.<clinit>(Unknown Source)
                                                               at org.libvirt.Library.<clinit>(Unknown Source)
                                                               at org.libvirt.Connect.<init>(Unknown Source)
                                                               at com.local.haris.MainActivity.onCreate(MainActivity.java:34)
                                                               at android.app.Activity.performCreate(Activity.java:6662)
                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                               at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                               at android.os.Looper.loop(Looper.java:154)
                                                               at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Notes: Android studio 3.0 Do not have the c++ SDK installed (didn't think I needed to since I am not compiling binaries) If am unsure if the libvirt java jar works on android. I tried to find information about this but failed to do. If someone could comment on this it would be appreciated.


回答1:


Include the libjnidispatch.so shared library for all the Android ABIs that your project supports.

  • Navigate to JNA libraries.
  • Under Version 4.5.0, download the zip archive
  • Unzip the package, navigate to jna-4.5.0/dist/ directory. libjnidispatch.so for different ABIs can be extracted from respective jar file. The mapping is as below illustrated in below table.

    | JNA ABI             | Android ABI   |
    | ------------------- | ------------- |
    | android-aarch64.jar | arm64-v8a     |
    | android-armv7.jar   | armeabi-v7a   |
    | android-x86-64.jar  | x86_64        |
    | android-x86.jar     | x86           |
    
  • Put the libjnidispatch.so into the mapped Android ABI folder, for example, arm64-v8a, armeabi-v7a, x86 and x86_64.


来源:https://stackoverflow.com/questions/53383745/android-jna-unsatisfiedlinkerror-native-library-com-sun-jna-xxx-libjnidispatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!