简体   繁体   English

android加载库失败

[英]android load library failed

When I use System.loadLibrary() to load my so file, rarely, it fails and the Logcat says 当我使用System.loadLibrary()加载我的so文件时,很少会失败,并且Logcat会说

Cannot load library: reloc_library[1286]: 121 cannot locate '__cxa_atexit'
java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:   169 cannot locate '__cxa_atexit'...
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)

After searching the Internet, I don't find any infomation about 搜索互联网后,我没有找到有关

cannot locate '__cxa_atexit'

(especially the key word __cxa_atexit). (尤其是关键字__cxa_atexit)。 Why cannot locate this function? 为什么找不到此功能? This function seems to be in libc.so. 该函数似乎在libc.so中。 I don't use C++ in my native code, only C. My NDK version is android-ndk-r10e. 我没有在本机代码中使用C ++,只有C。我的NDK版本是android-ndk-r10e。 I think "cannot locate __cxa_atexit" maybe a relative clue. 我认为“无法找到__cxa_atexit”可能是一个相对线索。

Most of the time (maybe billions starts of app), it can work well, but rarely crashes as above. 在大多数情况下(也许数十亿个应用启动),它可以正常工作,但很少像上面那样崩溃。 In other words, I cannot make it crash on my testing phones, however, it will crash rarely on some users'. 换句话说,我无法使其在我的测试手机上崩溃,但是,它很少会在某些用户的手机上崩溃。

This problem may be the same as another problem . 这个问题可能与另一个问题相同。

UPDATE 更新

Most of the phones which this crash happens on are android 4.0.3 and android 4.0.4. 发生此崩溃的大多数手机是android 4.0.3和android 4.0.4。 These two version are both API-15. 这两个版本都是API-15。

UPDATE 更新

After reading some Android's source code, I found this issue may be related to dlopen. 阅读一些Android的源代码后,我发现此问题可能与dlopen有关。 The error message "Cannot load library: reloc_library..." comes from the function dlopen which is hijacked at runtime. 错误消息“无法加载库:reloc_library ...”来自在运行时被劫持的函数dlopen。 The trace is runtime dlopen -> find_library -> init_library -> link_image -> reloc_library. 跟踪是运行时 dlopen-> find_library-> init_library-> link_image-> reloc_library。

Maybe when it resolve symbols in my so files, it finds the "__cxa_atexit" is undefined. 也许当它解析我的so文件中的符号时,它发现“ __cxa_atexit”未定义。 Then it looks up in the loaded symbols, but find nothing. 然后在加载的符号中查找,但什么也没找到。 (why cannot find __cxa_atexit ?) Finally it runs to the line 1285, with the code: (为什么找不到__cxa_atexit?)最后,它运行到第1285行,代码如下:

DL_ERR("%5d cannot locate '%s'...\n", pid, sym_name);

I don't know something about linker. 我对链接器一无所知。 Could anyone explain or guess why the __cxa_atexit cannot be located ? 任何人都可以解释或猜测为什么无法找到__cxa_atexit吗? Is it a bug of Android ? 这是Android的错误吗?

UPDATE 更新

It crashes on ALL Android versions, not only 4.0.3 & 4.0.4. 它在所有Android版本(不仅是4.0.3和4.0.4)上崩溃。

Error message on 4.0.3 & 4.0.4 is 关于4.0.3和4.0.4的错误消息是

java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1286]: 121 cannot locate '__cxa_atexit'

as mentioned above. 正如刚才提到的。

When loading some other so on 4.0.3 & 4.0.4, it is 当加载其他4.0.3和4.0.4时,它是

cannot locate 'strcpy'

Error message on 4.2.2 is 在4.2.2上的错误消息是

java.lang.UnsatisfiedLinkError: Cannot load library: load_library(linker.cpp:767): can't read file /mnt/asec/app-name-1/lib/libname.so: I/O error

Firstly, please make sure that you called System.loadLibrary() like below: 首先,请确保您像下面这样调用System.loadLibrary():

public class MainActivity extends Activity {
    static {
        System.loadLibrary("main")
    }
    ...
}

Then, according to the second answer in this post , the problem was with some external dependencies that were loaded statically in your native library. 然后,根据本文的第二个答案 ,问题出在本地库中静态加载的一些外部依赖项上。 They were only hanging on Android 4.0 and it was running fine 4.2 and up.So you should check your so file. 他们只是挂在Android 4.0上,并且运行良好的4.2及更高版本,因此您应该检查您的so文件。

I just put his answer here: 我只是把他的答案放在这里:

if you have the problem, put a __android_log_print in the JNI_onLoad of your library (if you have one). 如果有问题,请将__android_log_print放入库的JNI_onLoad中(如果有的话)。 If it is not called, check all the functions that can be called statically (beware, some might be hidden behind macros) and try to remove them to see if your able to load the library 如果未调用该函数,请检查所有可以静态调用的函数(注意,某些函数可能隐藏在宏后面),然后尝试将其删除以查看是否能够加载该库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM