4

我正在开发 android 应用程序,其中我将 JNI 用于本机 c 代码。我在 android 2.0 版本和 ndkr3 上构建了这个应用程序,它工作正常。

现在,当我更改 android sdk 1.5 版和 api 3 版时,我遇到了无法打开库 libtest_demo.so 的问题。

05-13 16:54:23.603: INFO/dalvikvm(1211): Unable to dlopen(/data/data/org.abc.test_demo/lib/libtest_demo.so): Cannot find library

我将 libtest_demo.so 文件放在同一位置 /data/data/org.abc.test_demo/lib/libtest_demo.so 但仍然出现同样的问题。

在我的 java 文件中,我调用了本地库,例如,

 System.loadLibrary("abc_jni");
 System.loadLibrary("test_demo");

从 logcat 我看到两个库都使用了相同的内存地址。

这是 logcat 输出

05-13 17:56:15.732: DEBUG/dalvikvm(9897): Trying to load lib /data/data/org.abc.test_demo/lib/libabc_jni.so 0x437317f8
05-13 17:56:15.732: DEBUG/dalvikvm(9897): Added shared lib /data/data/org.abc.test_demo/lib/libabc_jni.so 0x437317f8
05-13 17:56:15.742: DEBUG/dalvikvm(9897): Trying to load lib /data/data/org.abc.test_demo/lib/libtest_demo.so 0x437317f8 
05-13 17:56:15.752: INFO/dalvikvm(9897): Unable to dlopen(/data/data/org.abc.test_demo/lib/libtest_demo.so): Cannot find library
4

1 回答 1

7

This error almost always says "Cannot find library" and there can be many reasons for this. What is annoying is that in most cases it is not the missing library but something else. Reasons I have stumbled upon:

  • library is missing from the directory (obviously),
  • library that is dynamically linked with your library is missing,
  • system library versions on the device/emulator that your library uses differ with those that you were linking against in compile time (missing symbols, etc.)

I have described a method that worked for me when resolving an issue with library that was working fine on emulator and was failing to load on Nexus One, maybe this will help you: http://mpigulski.blogspot.com/2010/09/debugging-dlopen-unsatisfiedlinkerror.html

于 2010-09-16T08:24:36.250 回答