How Android JNI calls third-party libraries

Source: Internet
Author: User

http://www.2cto.com/kf/201504/388764.html
Android JNI solution for third-party libraries not found cannot l
Oad Library

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 := bb LOCAL_SRC_FILES := libbb.so include $(PREBUILT_SHARED_LIBRARY)
(<Dream> If a third party provides a. so file without the previous two steps)

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

LOCAL_PATH := $(call my-dir)  include $(CLEAR_VARS)  LOCAL_MODULE    := aa LOCAL_SRC_FILES := aa.cpp LOCAL_LDLIBS := -llog  LOCAL_SHARED_LIBRARIES := bb include $(BUILD_SHARED_LIBRARY) include $(LOCAL_PATH)/prebuilt/Android.mk (<Dream> can be statically linked to produce only one. So, as follows) Android.mak include $ (build_static_library) Application.mak App_modules:=aa

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);     } (<Dream> static link so that no load two libraries are required)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.

(<Dream> static link, please refer to this article)

Http://www.rosoo.net/a/201302/16514.html

How Android JNI calls third-party libraries

Related Article

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.