我已經成功地使用交叉在Android NDK 獨立的工具鏈編制了C++庫到Android。平臺。 我創建了一個新的android應用程序項目到Eclipse與jni dolder和Android.mk文件,當我做一個ndk構建建設順利,它將mylib.so添加到libs/armeabi文件夾 問題是當我做一個System.loadLibrary(「mylibname」); 我在logcat中出現以下錯誤: 無法dlopen(/data/data/com.oussama.firsttry/lib/libdash.so):無法加載庫:link_image [1995]:無法鏈接libdash.so 導致一個java.lang.UnsatisfiedLinkError:找不到我的lib **。沒有找到java.lang.UnsatisfiedLinkError中lib目錄下:(未鏈接mylib.so)
必須有我的LIB取決於和仿真器無法加載,所以我做了一個庫readelf -d mylib.so這裏是結果:
動態部分的偏移量0x1617c4包含26項:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libdash.so]
0x00000010 (SYMBOLIC) 0x0
0x0000000f (RPATH) Library rpath: [/home/oussama064/libdash/libdash/../../neededLibs]
0x00000019 (INIT_ARRAY) 0x157268
0x0000001b (INIT_ARRAYSZ) 172 (bytes)
0x0000001a (FINI_ARRAY) 0x157314
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0xf4
0x00000005 (STRTAB) 0x10f58
0x00000006 (SYMTAB) 0x50b8
0x0000000a (STRSZ) 134112 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x1618b4
0x00000002 (PLTRELSZ) 1096 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x40dd8
0x00000011 (REL) 0x31b38
0x00000012 (RELSZ) 62112 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000018 (BIND_NOW)
0x6ffffffb (FLAGS_1) Flags: NOW
0x6ffffffa (RELCOUNT) 7738
0x00000000 (NULL) 0x0
這裏是我的Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) LOCAL_MODULE := libcurl LOCAL_SRC_FILES :=
../../../../neededLibs/libcurl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libxml LOCAL_SRC_FILES :=
../../../../neededLibs/libxml2.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := libz LOCAL_SRC_FILES :=
../../../../neededLibs/libz.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS) LOCAL_MODULE := m LOCAL_SRC_FILES :=
libm.so include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS)
LOCAL_MODULE := dl LOCAL_SRC_FILES := libdl.so
include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE
:= c LOCAL_SRC_FILES := libc.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := d LOCAL_SRC_FILES := libdash.so
LOCAL_SHARED_LIBRARIES := c m dl
LOCAL_STATIC_LIBRARIES := libz libxml libcurl include
$(PREBUILT_SHARED_LIBRARY)
我'現在真的卡住,我想不出w ^帽子是缺少庫
當我做一個NDK建造V = 1 -B我得到以下結果:
rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/lib*.so
/家庭/ oussama064 /安卓/工作區/ FirstTry /庫/ armeabi-V7A /lib*.so /home/oussama064/Android/workspace/FirstTry/libs/mips/lib*.so /home/oussama064/Android/workspace/FirstTry/libs/x86/lib*.so rm -f/home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/mips/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/x86/gdbserver rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdb.setup /home/oussama064/Android/workspace/FirstTry /libs/armeabi-v7a/gdb.setup /home/oussama064/Android/workspace/FirstTry/libs/mips/gdb.setup /home/oussama064/Android/workspace/FirstTry/libs/x86/gdb.setup make :圓形obj/local/armeabi/libm.so < - obj/local/armeabi/libm.so依賴關係 已下降。 make:Circular obj/local/armeabi/libm.so < - obj/local/armeabi/libc.so dependency dropped。 make:Circular obj/local/armeabi/libdl.so < - obj/local/armeabi/libm.so dependency dropped。 make:Circular obj/local/armeabi/libdl.so < - obj/local/armeabi/libc.so dependency dropped。 make:Circular obj/local/armeabi/libdl.so < - obj/local/armeabi/libdl.so dependency dropped。 預建:libdl.so < = /家庭/ oussama064 /安卓/工作區/ FirstTry/JNI/ CP -f /home/oussama064/Android/workspace/FirstTry/jni/libdl.so
OBJ /本地/ armeabi/libdl .so 預建:libm。所以< =/home/oussama064/Android/workspace/FirstTry/jni/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/libm.so obj/local/armeabi/libm.so make:Circular obj /local/armeabi/libc.so < - 刪除了obj/local/armeabi/libc.so依賴項。 Prebuilt:libc.so < =/home/oussama064/Android/workspace/FirstTry/jni/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/libc.so obj/local/armeabi/libc.so 安裝:libc.so => /home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so 安裝-p ./obj/local/armeabi/libc.so
/家/ oussama064/Android的/workspace/FirstTry/libs/armeabi/libc.so /home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi- 4.6/prebuilt/linux-x86/bin/arm-linux-androideabi -strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so 預建:libxml2.a < =
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/ CP -f
/家/ oussama064/Android設備/工作區/ FirstTry/JNI/../../../../neededLibs/libxml2.a obj/local/armeabi/libxml2.a 預建:libcurl.a < = /home/oussama064/Android/workspace/FirstTry/jni /。 ./../../../neededLibs/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libcurl.a
obj/local/armeabi/libcurl.a 預建:libdash.so < =/home/oussama064/Android/workspace/FirstTry/jni/
cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdash.so
obj/local/armeabi/libdash.so
Install : libdash.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
install -p ./obj/local/armeabi/libdash.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
Install : libdl.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
install -p ./obj/local/armeabi/libdl.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so /家庭/ oussama064/NDK/Android的NDK-R 8d中/工具鏈/ ARM-Linux的androideabi-
4.6 /預建/ Linux的-86 /斌/ ARM-Linux的androideabi條--strip-不需要
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
Install : libm.so =>
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
install -p ./obj/local/armeabi/libm.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
我會心存感激,如果任何人能幫助我。
好吧,你正在嘗試加載'mylib.so',但是你只有'libdash.so'。如果這不是問題,請編輯錯誤信息,請複製並粘貼正確的錯誤文本。 – 2013-03-21 07:53:00
你應該在問題中給出正確的描述,你試圖加載哪個庫?無論如何,我的兩分錢是你應該haved使用System.loadLibrary(「破折號」) – auselen 2013-03-21 08:32:32
我已經完成System.loadLibrary(「破折號」); 就像我在錯誤信息中看到的,android實際上在libs/armeabi/libdash.so下找到lib – 2013-03-21 08:46:08