Android NDK loads so in SD card

Source: Internet
Author: User

Android NDK loads so in SD card

Recently, the company's framework has just been transplanted. Since the framework program needs to call subroutines, each subroutine is a so file, with hundreds of so files. It is unrealistic to package all the so and apk files, timely upgrade and maintenance are also troublesome. So you need to put it in the SD card. Two methods

1

Put it in the/data/app-lib/package name/so file on the device (another default path does not remember) and copy it to this path during program initialization, loadlibrary is loaded from two default paths.

In this way, the device requires root, which is less efficient. If the app is uninstalled, all the so files are gone.

2

Directly put it in the SD card, open so in the SD card through dlopen, and then find the function address in dlsym.

# Include dlfcn. h // dlopen header file void (* pf_threadcannback) (); // declare function pointer type void (* pf_program) (); void * handle; bool getMethod () {handle = dlopen (// storage // emulated // 0 // lib // libprogram. so, RTLD_NOW); // dlopen (/storage/emulated/0/lib/libtwolib-second.so, RTLD_NOW); if (! Handle) {__ android_log_print (ANDROID_LOG_INFO, JNIMsg, Your params is null: % s, dlerror ();} else {__ android_log_print (bytes, JNIMsg, Your params is GOOD2 );} pf_program = dlsym (handle, myFunc); // point to the function name pf_threadcannback = dlsym (handle, ThreadCallBack) in so; if (dlerror ()) {__ android_log_print (ANDROID_LOG_INFO, JNIMsg, dlsym no error); return false ;}return true; // call/dlclose (handle) when the recommendation program is released and exited );}
Find the function address and execute it directly. 

 

For example, if you want to call the myFunc () function in so to execute pf_program (), it will be OK.

 

 

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.