无法在Android的NDK建立当地的共享库 [英] Cannot build local shared library in Android Ndk

查看:815
本文介绍了无法在Android的NDK建立当地的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建库。所以为4.0.3版本,但我不能这样做。 我的感觉是,这些问题造成的,因为我的.mk文件不是 链接与库。

I want to build library .so for version 4.0.3 but I am unable to do so. What I feel is that these problems are caused because my .mk file is not linking with the libraries.

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)

该文件生成静态的,即某文件对我来说却显示了以下错误,同时建立共享库。

This file builds static i.e .a file for me but shows following errors while building shared 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

I fixed above errors using LOCAL_CFLAGS += -DHAVE_PTHREADS

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

But now, at the time of generating library I am getting a huge list of errors.

   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&)'

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

的Andr​​oid NDK支持的pthread S,但不提供的libpthread 像往常一样在Linux的工具链。将离开你的第一个错误信息,如果您使用

Android NDK supports pthreads, but does not provide libpthread as usual in Linux toolchains. Your first error message will be gone if you use

LOCAL_CFLAGS += -DHAVE_PTHREADS

和不添加 LOCAL_LDLIBS + = -lpthread

对于未定义的引用 do_copy(),它来自系统库 libutils.so 。这是不安全的使用没有与官方公布的NDK库(看更多这里),所以你最好重写这块的code。

Regarding the undefined reference to do_copy(), it comes from system library libutils.so. It is not safe to use libraries that are not officially published with NDK (see more here), so you better rewrite this piece of code.

也许你从 Android.mk 文件=htt​​ps://android.googlesource.com/platform/frameworks/native/ + /主/库/粘合剂/ Android.mk相对=nofollow>谷歌源 或它的叉之一。我怀疑,产生的库将是可用的,因为原来的 libbinder.so 需要提升的权限将您的应用程序启动时加载的系统应用程序。

Probably you received your Android.mk file from the google source or one of its forks. I doubt that the resulting library will be useable, because the original libbinder.so requires system app with elevated permissions will be loaded when your app starts.

不管怎么说,指的是系统库为 LOCAL_SHARED_LIBRARIES 不与 NDK建造工作。而不是 LOCAL_SHARED_LIBRARIES:= liblog libcutils libutils 我们希望你写

Anyways, referring to system libraries as LOCAL_SHARED_LIBRARIES does not work with ndk-build. Instead of LOCAL_SHARED_LIBRARIES := liblog libcutils libutils you are expected to write

LOCAL_LDLIBS += -llog -lcutils -lutils

这篇关于无法在Android的NDK建立当地的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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