Android app calls so and reports dlopen failed: library “libnativehelper.so” not found solution

1. Problem phenomenon

During the development of android NDK, the APP calls the so library and the following problems occur

Two, the cause of the problem

The main reason is that Google restricts the loading of the .so library on N, which restricts the loading of the so library from a partially specified path. The so that is not in this path prompts java.lang.UnsatisfiedLinkError: dlopen failed: library “ 
xxx.so " not found or 
java.lang.UnsatisfiedLinkError: dlopen failed: library "/vendor/lib64/xxx.so" needed or dlopened by "/system/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace" or Other abnormal error prompts.

The search path for loading the so library on N is ld_library_path, runtime path, permit path, if it is not in this search path, the loading will fail. From the code level, it is mainly related to the processing of the class loader ClassLoader, 

​
//code1: (loadedApk.java getClassLoader()) check sdk version 
// DO NOT SHIP: this is a workaround for apps loading native libraries 
// provided by 3rd party apps using absolute path instead of corresponding 
// classloader; see http://b/26954419 for example. 
if (mApplicationInfo.targetSdkVersion <= 23) { 
libraryPermittedPath += File.pathSeparator + “/data/app”; 
}

//Code2: (loadedApk.java getClassLoader()) N add a new PermittedPath 
String libraryPermittedPath = mDataDir;

//Code3: (native_loader.cpp) use the new namespace rule with search path: ld_library_path, //runtime path, permit path.

​

Three, the solution

Add your own so to the whitelist of allowed paths. The specific operation is, if you do not change the code to implement, export the /vendor/etc/public.libraries.txt or /etc/public.libraries.txt file of the device, and copy the so Add the name, push to the device, and restart.

 

Guess you like

Origin blog.csdn.net/BersonKing/article/details/130124071
Recommended