A small case of java. lang. UnsatisfiedLinkError

Source: Internet
Author: User

A small case of java. lang. UnsatisfiedLinkError

Third-party dynamic library. so files are used in many projects, but they often cause a lot of troubles, such as java. lang. UnsatisfiedLinkError.

 

06-17 15:52:08.097    7876-7916/com.ishow.scan E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-61542    java.lang.UnsatisfiedLinkError: Native method not found: com.ishow.scan.zbar.ZbarManager.decode:([BIIZIIII)Ljava/lang/String;            at com.ishow.scan.zbar.ZbarManager.decode(Native Method)            at com.ishow.scan.decode.DecodeHandler.decode(DecodeHandler.java:58)            at com.ishow.scan.decode.DecodeHandler.handleMessage(DecodeHandler.java:39)            at android.os.Handler.dispatchMessage(Handler.java:107)            at android.os.Looper.loop(Looper.java:194)            at com.ishow.scan.decode.DecodeThread.run(DecodeThread.java:45)

No matter what you do, this error is reported and annoying. I started to use Android studio and began to understand how to import dynamic library files. After all, Android studio is different from eclipse, in the libs directory. so files are useless, so I finally got some help from Q group. I sorted them out and shared them with readers by the way.

 

Method 1: (the simplest method)

Create a folder named jniLibs in the main directory and import the dynamic library file to the folder,

 

In this way, you can import the. so dynamic library file to Android studio. However, no matter how I run it, the java. lang. unsatisfiedLinkError is abnormal. I began to suspect that the imported dynamic library file cannot be found in Android studio, but it is reasonable to say that this error should not be reported if my inference is incorrect. As a result, I continued to search for the method for importing dynamic library files to Android studio. Huang Tian was very considerate and I learned another method,

This method involves the following steps:

1. Create a folder named lib in Windows

2. Copy the dynamic library file to the lib directory, and store the. so file in the armeabi directory.

3. Use zip to package the lib folder and rename it: armeabi. jar

4. Copy armeabi. jar to the libs directory of the Android studio project.

 

 

The second method is used to import the dynamic library file to Android studio, but java still appears at runtime. lang. unsatisfiedLinkError is abnormal. However, I thought it was a ghost of Android studio. Maybe I am not familiar with Android studio. However, when I switch to eclipse, create a project, and continue to complete my work (the project that scans the QR code), after everything is ready, run the project, or java appears. lang. unsatisfiedLinkError is abnormal and I am going crazy. So I calmed down and thought: It is impossible for both eclipse and Android studio to see java. lang. UnsatisfiedLinkError. Except for the first time, I always went into a wrong "trap ". Yes, the problem is finally clarified. The problem must be the class that loads the library file. After further exploration, I wrote an error about the package name of the library file. This package name cannot be named at will and must be strictly followed by the package name specified by Android. mk in the library file. So I changed the package name to com. zbar. lib (an error was reported when com.ishow.org. zbar was originally used). After the package name was changed back, the problem was finally solved!

 

To solve the jni issue, you need to pay attention to the need to reference the dynamic library file and the package name corresponding to the class for loading the dynamic library file, which must be consistent with Android. the package names defined in mk are consistent, otherwise java will appear. lang. unsatisfiedLinkError. If this article is helpful to you, please leave a footprint. Thank you.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.