我目前正在开发一款Android应用程序,该应用程序利用用C编写的现有本机库。
我设法在摩托罗拉Moto G2(Android 6.0,armeabi-v7a)上运行应用程序,但在Galaxy S2(Android 4.1.2,也是armeabi-v7a)上,我总是得到DllNotFoundException
。< / p>
当我运行adb shell ls -l /data/data/com.my.app/lib
时,我可以看到libmyutils.so
是从相应的ABI lib文件夹中提取的。
在调试日志中可以看到很多这样的行:
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library './libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/./libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library './libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library '/system/lib/libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib//system/lib/libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library '/system/lib/libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'myutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/myutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library './libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/./libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library './libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library '/system/lib/libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib//system/lib/libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library '/system/lib/libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/libmyutils' not found'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'libmyutils.so': 'Cannot load library: find_library[1202]: 138 'libmyutils.so' failed to load previously'.
01-25 15:44:55.397 D/Mono (27537): DllImport error loading library 'libmyutils': 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/libmyutils' not found'.
01-25 15:44:55.397 W/Mono (27537): DllImport unable to load library 'Cannot load library: load_library[1094]: Library '/data/data/com.my.app/lib/libmyutils' not found'.
这是编译器/架构问题吗?
我期待着你的帮助!
最佳, 马可
更新:解决方案
最后它有效!在Galaxy S2 Android 4.1.2上,我尝试使用DllImport
属性调用本机函数,并将库指定为myutils
。在我将myutils
更改为libmyutils.so
后,应用程序可以找到该库。不幸的是,它找不到依赖库libdep1.so
。我所做的是在启动时使用Java.Lang.JavaSystem.LoadLibrary("dep1")
然后Java.Lang.JavaSystem.LoadLibrary("myutils")
以正确的顺序加载库。即使没有 lib 和 .so pre / / suffix,也只使用库名称。我还可以切换回libmyutils.so
属性库名称中的myutils
到DllImport
。