Android JNI cannot find a solution for a third-party library cannot load library

Source: Internet
Author: User

In a recent JNI project, the so library was given a layer of JNI encapsulation, equal to the method of invoking a third-party library in the JNI C + + code, and the entire project ran on Android.

The third-party library that Libaa.so uses for its own JNI generation is libbb.so.

So far, the problem encountered is that libbb a variety of can not find. Where's the LIBBB library?


E/androidruntime (11626): caused by:java.lang.UnsatisfiedLinkError:

Cannot load Library:soinfo_link_image (linker.cpp:1640):
Could not load library "libbb.so" needed by "libaa.so";

Caused by Load_library (linker.cpp:750): library ' libbb.so ' not found


The above error occurs in the run phase, in fact, the compilation phase also occurred in the problem of finding a third party, the performance is the library implementation of the method undefined.

Resolved in two ways


1, the compilation phase can not find the library, need to modify the Mk file.

1.libbb.so put in the Jni/prebuilt folder (own new), while the android.mk copy to prebuilt.

2.Libbb.so's MK is as follows:

Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = bblocal_src_files: = Libbb.soinclude $ (prebuilt_shared _library)

3.libaa.so's MK file needs to be introduced in the above Mk.

Local_path: = $ (call My-dir) include $ (clear_vars) local_module    : = aalocal_src_files: = aa.cpplocal_ldlibs: =- Lloglocal_shared_libraries: = Bbinclude $ (build_shared_library) include $ (local_path)/prebuilt/android.mk

This allows you to connect to a third-party library during the compile phase.


2. Library not found at run stage

The library is not found in the run phase is the android thing. Later discovered is the order of the load library (a silent, broken sequence. )。

static {system.loadlibrary ("BB"); System.loadlibrary ("AA");    }
Load the third-party library first, and then load your own library, because the AA library to use the BB library method, is dependent on the BB Library, so the first load.


This will also find the library at run time.

Android JNI cannot find a solution for a third-party library cannot load library

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.