Android : Overcome System.loadlibrary(); issue abo

2019-09-05 09:14发布

I am working on APV pdf reader. I am facing System.loadLibrary("pdfview2"); error. It's giving java.lang.UnsatisfiedLinkerror.
How to fix this issue? I installed Android-NDK also, but not getting how to load native libraries. Full confusion. Please suggest me a way to fix this issue.

09-26 12:51:44.243: E/AndroidRuntime(2537): FATAL EXCEPTION: main
09-26 12:51:44.243: E/AndroidRuntime(2537): java.lang.ExceptionInInitializerError
09-26 12:51:44.243: E/AndroidRuntime(2537):     at cx.hell.android.pdfview.OpenFileActivity.getPDF(OpenFileActivity.java:541)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at cx.hell.android.pdfview.OpenFileActivity.startPDF(OpenFileActivity.java:502)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at cx.hell.android.pdfview.OpenFileActivity.onCreate(OpenFileActivity.java:219)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.os.Looper.loop(Looper.java:123)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at java.lang.reflect.Method.invoke(Method.java:507)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at dalvik.system.NativeStart.main(Native Method)
09-26 12:51:44.243: E/AndroidRuntime(2537): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load pdfview2: findLibrary returned null
09-26 12:51:44.243: E/AndroidRuntime(2537):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at java.lang.System.loadLibrary(System.java:554)
09-26 12:51:44.243: E/AndroidRuntime(2537):     at cx.hell.android.lib.pdf.PDF.<clinit>(PDF.java:25)
09-26 12:51:44.243: E/AndroidRuntime(2537):     ... 16 more

Hi i attached the log report .its giving :- Caused by: java.lang.UnsatisfiedLinkError: Couldn't load pdfview2: findLibrary returned null

4条回答
孤傲高冷的网名
3楼-- · 2019-09-05 09:28

Another reason for this failure, in my experience, is the presence of libs/armeabi and not libs/armeabi-v7a. Copy the contents of libs/armeabi into a new folder named libs/armeabi-v7a.

查看更多
女痞
4楼-- · 2019-09-05 09:28

1- make sure name of native function Java_package_className_methodName

2- APP_ABI := all64 //defined in jni/Application.mk

查看更多
The star\"
5楼-- · 2019-09-05 09:37

After building your project, look in the libs/ folder for the resulting .so. If you're building for ARM, is there an armeabi or armeabi-v7a folder with your .so in it? You can set the architectures you want to support in jni/Application.mk with the APP_ABI variable.

APP_ABI := armeabi armeabi-v7a x86 mips

will build your library for all of the possible supported architectures.

Don't forget that Android's dynamic linker is dumb and won't load library dependencies automatically. If you're using C++ code with gnustl_shared, for example, you'll need to load that before any libraries that are linked against it.

static {
    System.loadLibrary("gnustl_shared");
    System.loadLibrary("a_cplusplus_library");
}
查看更多
登录 后发表回答