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.