无法在Android Ndk中创建本地共享库

问题描述:

我想为4.0.3版本构建库.so,但我无法这样做。 我的感觉是,这些问题是由于我的.mk文件不是 链接库。无法在Android Ndk中创建本地共享库

Android.mk文件

Binder.cpp \ 
BpBinder.cpp \ 
CursorWindow.cpp \ 
IInterface.cpp \ 
IMemory.cpp \ 
IPCThreadState.cpp \ 
IPermissionController.cpp \ 
IServiceManager.cpp \ 
MemoryDealer.cpp \ 
MemoryBase.cpp \ 
MemoryHeapBase.cpp \ 
MemoryHeapPmem.cpp \ 
Parcel.cpp \ 
PermissionCache.cpp \ 
ProcessState.cpp \ 
Static.cpp 

LOCAL_PATH:= $(call my-dir) 
include $(CLEAR_VARS) 
LOCAL_LDLIBS += -lpthread 
LOCAL_MODULE := libbinder1 
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils 
LOCAL_SRC_FILES := $(sources) 
include $(BUILD_SHARED_LIBRARY) 

#include $(CLEAR_VARS) 
#LOCAL_CFLAGS += -DHAVE_PTHREADS 
#LOCAL_LDLIBS += -lpthread 
#LOCAL_MODULE := libbinder 
#LOCAL_SRC_FILES := $(sources) 
#include $(BUILD_STATIC_LIBRARY) 

此文件构建静态即某文件对我,而且下面显示了错误,同时建立共享库。

[armeabi] Compile++ thumb: binder1 <= IPCThreadState.cpp 
jni/IPCThreadState.cpp:292:8: error: 'pthread_mutex_t' does not name a type 
jni/IPCThreadState.cpp:294:8: error: 'pthread_key_t' does not name a type 
jni/IPCThreadState.cpp: In static member function 'static android::IPCThreadState*  android::IPCThreadState::self()': 

我固定使用 LOCAL_CFLAGS上述错误+ = -DHAVE_PTHREADS

但现在,在生成库我得到一个巨大的错误列表的时间。

D:/android-ndk-r9c-windows-x86/android-ndk-r9c/toolchains/arm-linux-androideabi-  4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux- androideabi/bin/ld.exe: error: cannot find -lpthread 
D:/android-ndk-r9c-windows-x86/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/binder1/Binder.o: in function android::Vector<android::String16>::do_copy(void*, void const*, unsigned int) const:jni/utils/TypeHelpers.h:142: error: undefined reference to 'android::String16::String16(android::String16 const&)' 

任何帮助将不胜感激。

+0

你在构建系统树这个项目,或者用'NDK-build'? –

+0

ndk-build ...我不知道什么是系统树!我是NDK新手 – Mohit

+0

这个库应该做什么?你从哪里获得代码库? –

Android NDK支持pthread s,但并不像平常一样在Linux工具链中提供libpthread。如果你使用

LOCAL_CFLAGS += -DHAVE_PTHREADS 

,而不是添加LOCAL_LDLIBS += -lpthread

关于未定义参考do_copy()你的第一个错误信息将会消失,它来自系统库libutils.so。使用未与NDK正式发布的库并不安全(请参阅更多here),因此您最好重写这段代码。

也许你从google source或其叉的一个收到你Android.mk文件。我怀疑由此产生的图书馆将是可用的,因为原来的libbinder.so需要具有提升的权限的系统应用程序将在您的应用程序启动时加载。

无论如何,系统库参考LOCAL_SHARED_LIBRARIES不适用于ndk-build。取而代之的LOCAL_SHARED_LIBRARIES := liblog libcutils libutils你预计写

LOCAL_LDLIBS += -llog -lcutils -lutils 
+1

你似乎暗示的是,海报试图使用不导出到NDK的平台/ AOSP内部功能。但是,您所说的方式并不十分准确,似乎会混淆*​​ exports * vs * permissions *的问题,例如,如果您检查第三方应用程序的进程,则会发现libbinder.so一个依赖项(一个已经由zygote加载) - 实际上并不需要“具有提升权限的系统应用程序”,尽管它不适用于第三方代码直接进行交互,并且对于任何有用的使用都会非常棘手。 –

+0

@ChrisStratton感谢您的澄清。我确认'libbinder.so'可以在用户进程中加载​​。 –