Android NDK calls Third-party library files and cannot find a third-party library solution

Source: Internet
Author: User

how to invoke a third party library file (. So) in the Android NDK



1. Create a prebuilt subdirectory under the Project/jni directory (directory name customizable).

2. Put the third party. So in the prebuilt and create the ANDROID.MK, as follows:

Local_path: = $ (call My-dir)

Include $ (clear_vars)

Local_module: = xxx

Local_src_files: = libxxx.so

Include $ (prebuilt_shared_library)

3. Add in Project/jni/android.mk

Local_shared_libraries: = xxx

4. In the final part of the PROJECT/JNI/ANDROID.MK

Include $ (local_path)/prebuilt/android.mk

5. Run Cygwin, go to project directory, run $ndk/ndk-build




Android Jni can't find a solution to a third-party library cannot load library



A recent JNI project, get the so library need to use JNI package a layer, is tantamount to the JNI C + + code to call the Third-party library method, and then the entire project on Android to run the results.

The third-party library used by the libaa.so, which is generated by its own JNI, is libbb.so.

So far, the problem is that libbb can't be found. LIBBB, where's the 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 errors occur in the run-time phase, in fact, the compilation phase has also been unable to find a third party problem, performance is the library implementation of the method undefined.

Be solved in two ways



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

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

The Mk 2.libbb.so 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, you do not need the previous two steps)

3.libaa.so's MK files need to be introduced to 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, which produces 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 in the compile phase.

2. The runtime could not find the library

It's Android to not find the library at run time. Later found is the order of the load library (a moment of silence, broken order.) )。


Static
{
System.loadlibrary (BB);
System.loadlibrary (AA);
}
(<Dream> static links so that you don't need to load two libraries)
First load third party library, and then load their own library, because the AA library to use the BB library method, is dependent on the BB Library, so first load.

This can also be found in the run-time phase of the library slightly.

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.