Android NDK loaded on SD card so

Source: Internet
Author: User

Recently the company framework has just been transplanted, because the framework program to call subroutines, each subroutine is a so file, there are hundreds of, all so and apk packaging unrealistic, timely upgrade maintenance is also very troublesome. So you need to put the SD card. Consider two different ways

1

The/data/app-lib/package name/so file that is placed on the device (and a default path is not remembered) is copied to this path when the program is initialized, and LoadLibrary is loaded from the two default paths.

This way the device needs to be rooted, less efficient, and if the application is unloaded all so is gone.

2

directly into the SD card via Dlopen open the SD card so then Dlsym Find the function address

#include "dlfcn.h"//dlopen header file Void (*pf_threadcannback) ();//Declaration 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 (android_log_info, "jnimsg", "Your params is GOOD2");} Pf_program = Dlsym (handle, "<span style=" Color:rgb (Wuyi, Wuyi, Wuyi); font-family:arial; font-size:14px; line-height:26px ;" >myFunc</span> ");     Point to the function name you want to call in so Pf_threadcannback = Dlsym (handle, "Threadcallback"), if (Dlerror ()) {__android_log_print (android_ Log_info, "Jnimsg", "Dlsym no Error"); return false;} return true;//Call//Dlclose (handle) When releasing resource recommendation program exit;}
The function address is found and then executed directly.

For example, to invoke the MyFunc () function in so to execute Pf_program () is OK.

Demo Address


Android NDK loaded on SD card so

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.