Android的加载库失败 [英] android load library failed

查看:432
本文介绍了Android的加载库失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用的System.loadLibrary()加载我这样的文件,很少,失败和logcat的说:

 无法加载库:reloc_library [1286] 121找不到'__cxa_atexit
java.lang.UnsatisfiedLinkError中:无法加载库:reloc_library [1285] 169找不到'__cxa_atexit......
在java.lang.Runtime.loadLibrary(Runtime.java:370)
在java.lang.System.loadLibrary(System.java:535)

在网上搜索后,我没有找到任何信息来源

 找不到'__cxa_atexit

(特别是关键词__cxa_atexit)。为什么无法找到这个功能呢?此功能似乎是在libc.so.我没有在我的本地code使用C ++中,只有C.我的NDK版本是Android的NDK-r10e。我认为,无法找到__cxa_atexit也许一个相对的线索。

大多数时候(应用程序也许十亿次首发),它可以很好地工作,但正如上文很少崩溃。换句话说,我不能让但它崩溃我的测试手机,它很少崩溃在一些用户的。

此问题可能是相同<一href=\"http://stackoverflow.com/questions/32796782/loading-android-so-sometimes-fails-rarely?lq=1\">another问题。

更新

其中大部分这种崩溃发生在手机都是安卓4.0.3和android 4.0.4。这两个版本均API-15。

更新

阅读一些Android的源代码code之后,我发现这个问题可能执行dlopen有关。错误消息无法加载库:reloc_library ......来自它在运行时劫持功能的dlopen。跟踪是运行的dlopen - > find_library - > init_library - > link_image - > reloc_library

也许当它在我这样的文件解析符号,它发现__cxa_atexit是不确定的。然后,它查找在加载符号,但是一无所获。 (为什么找不到__cxa_atexit?),最后,它运行到该行1285,用code:

  DL_ERR(%5D无法找到'%s'的... \\ N,PID,sym_name);

我不知道一些关于连接器。任何人都可以解释或者猜测为什么__cxa_atexit无法定位?它是Android的一个错误吗?

更新

它崩溃的所有Android版本,不仅4.0.3&安培; 4.0.4。

在4.0.3和放大器的错误消息; 4.0.4

  java.lang.UnsatisfiedLinkError中:无法加载库:reloc_library [1286] 121找不到'__cxa_atexit

如上所述

当加载一些其他的依此类推4.0.3&安培; 4.0.4,它是

 找不到'的strcpy

4.2.2错误消息

  java.lang.UnsatisfiedLinkError中:无法加载库:load_library(linker.cpp:767):无法读取文件到/ mnt / ASEC /应用程序名称-1 / lib目录/ LIBNAME的.so:I / O错误


解决方案

首先,请确保你叫的System.loadLibrary()象下面这样:

 公共类MainActivity延伸活动{
    静态的 {
        的System.loadLibrary(主)
    }
    ...
}

然后,根据<一href=\"http://stackoverflow.com/questions/8562706/android-system-loadlibrary-stalls-while-loading-native-library\">the在这个岗位第二个答案,
问题是与人在你的本地库静态加载一些外部的依赖。他们只是挂在Android 4.0及它运行良好4.2和up.So你应该检查你这样的文件。

我只是把他的答案在这里:

如果您有问题,把__android_log_print在库中的JNI_onLoad(如果有的话)。如果它不叫,检查可以静态调用的所有函数(注意,有些人可能被隐藏背后的宏),并试图删除它们,看看你能加载库

When I use System.loadLibrary() to load my so file, rarely, it fails and the Logcat says

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). Why cannot locate this function? This function seems to be in libc.so. I don't use C++ in my native code, only C. My NDK version is android-ndk-r10e. I think "cannot locate __cxa_atexit" maybe a relative clue.

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. These two version are both API-15.

UPDATE

After reading some Android's source code, I found this issue may be related to dlopen. The error message "Cannot load library: reloc_library..." comes from the function dlopen which is hijacked at runtime. The trace is runtime 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. 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:

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 ? Is it a bug of Android ?

UPDATE

It crashes on ALL Android versions, not only 4.0.3 & 4.0.4.

Error message on 4.0.3 & 4.0.4 is

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

cannot locate 'strcpy'

Error message on 4.2.2 is

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:

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.

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). 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

这篇关于Android的加载库失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆