Android ndk calls third-party so

Source: Internet
Author: User

Http://www.eoeandroid.com/thread-55467-1-1.html

First of all, you need to determine whether your. so is supported by android, not all. so can be, itself is divided into linux-X86 and linux-arm two categories. Check whether so is compiled into so in ARM mode.

$ File libtest. so

Libtest. so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped. PS ndk-build generated. so is certainly supported.

Http://kaneiqi.iteye.com/blog/666816

Http://blog.csdn.net/victoryckl/article/details/6832333

Http://blog.csdn.net/vrix/archive/2010/03/06/5351196.aspx
There is an so file named "libold. so ". The method "int oldmethod ()" is provided ()".
Now, for some reason, the interface changes, or you do not know old. so interface, but the oldmethod method is used. Therefore, use a new interface. If the interface is "jint Java_com_example_newmethod (JNIEnv *, jobject )"
Generate a new so file for use.

The mynewlib. c file is as follows:
# Include <string. h>
# Include <jni. h>
# Include <dlfcn. h>
Jint

Java_com_example_tnewmethod (jnienv * ENV, jobject thiz)

{
Void * filehandle = dlopen ("/data/COM. Example/lib/libold. So", rtld_lazy); // open the original so file
If (filehandle)
{
INT (* oldmethod )();
Oldmethod = dlsym (filehandle, "oldmethod"); // introduce the function in the original so
If (oldmethod)
{
// Call this function
}
}
}
Here, dlopen and dlsym are functions in libdl. so under/system/lib in android. Therefore, you need to export this file from android and directly use pull in the simulator. If so is not linked during compilation, compilation fails. With this file, Android. mk is as follows:

LOCAL_PATH: = $ (call my-dir)

LOCAL_MODULE: = my-new-lib
LOCAL_SRC_FILES: = mynewlib. c
# Here, libdl. so is linked. It seems to be placed in the ANDROID_NDK_ROOT path. If not, you can find the correct path based on the Compilation error information.
LOCAL_LDLIBS: =-L.-ldl

Include $ (BUILD_SHARED_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.