写binder客户端与服务端碰到的编译错误

调试C++使用binder进行两个进程通讯的代码编译错误,记录下来给朋友们作为参考:


1、BpBInder端客户端函数未定义,如
target SharedLib: libgui (out/target/product/generic/obj/SHARED_LIBRARIES/libgui_intermediates/LINKED/libgui.so)
out/target/product/generic/obj/SHARED_LIBRARIES/libgui_intermediates/IPlayerServer.o:(.data.rel.ro._ZTVN7android11BnInterfaceINS_13IPlayerServerEEE[vtable for android::BnInterface]+0x20): undefined reference to `android::IPlayerServer::handleToPlayerid(int, int)'


class IPlayerServer : public IInterface
{
public:
    DECLARE_META_INTERFACE(PlayerServer);


    virtual Vector getPlayerList() = 0;
    virtual int handleToPlayerid(int type, int handle) ;
};


这是由于虚函数定义没有默认实现的问题 
改成如此即可 
virtual int handleToPlayerid(int type, int handle) =0;


2、BpBinder端没有对Flattenable interface进行定义实现
target thumb C++: libgui <= frameworks/base/libs/gui/Player.cpp
frameworks/base/libs/gui/Player.cpp:63: error: no 'size_t android::Player::getFlattenedSize() const' member function declared in class 'android::Player'
frameworks/base/libs/gui/Player.cpp:72: error: no 'size_t android::Player::getFdCount() const' member function declared in class 'android::Player'


增加:
    // Flattenable interface
    virtual size_t getFlattenedSize() const;
    virtual size_t getFdCount() const;
    virtual status_t flatten(void* buffer, size_t size,
            int fds[], size_t count) const;
    virtual status_t unflatten(void const* buffer, size_t size,
            int fds[], size_t count);
并实现即可


3、未继承class RefBase 类导致问题
frameworks/base/include/utils/RefBase.h:331: error: 'class android::PlayerDevice' has no member named 'decStrong'
frameworks/base/include/utils/RefBase.h: In member function 'android::sp& android::sp::operator=(T*) [with T = android::PlayerDevice]':
frameworks/base/services/multiplayerservice/MultiplayerService.cpp:55:   instantiated from here
frameworks/base/include/utils/RefBase.h:346: error: 'class android::PlayerDevice' has no member named 'incStrong'
frameworks/base/include/utils/RefBase.h:347: error: 'class android::PlayerDevice' has no member named 'decStrong'


增加一下RefBase类即可
class PlayerDevice:
public Singleton,
public RefBase
{


4、汇编代码问题(linear_src.c 中使用assemble.h)
/tmp/ccVb1LeR.s: Assembler messages:
/tmp/ccVb1LeR.s:476: Error: selected processor does not support `smull r6,r1,r3,r1'


网上找的答案是:
ALWAYS_BUILD_AS_ARM
放置在mmp第一行,可以避免各类SDK版本下编译内嵌arm汇编码出现thumb指令集导致的编译错误
症状类似:
gcce编译器的
Error: selected processor does not support `smull r0,r3,r6,r3′
armcc编译器的
Inline assembler not permitted when generating Thumb code
__asm {
...
}

由于assembly.h是以inline定义,代码宏替换后报错,所以在gcc make编译选项中想办法:
在编译此文件中加入 
LOCAL_CFLAGS += -mno-thumb-interwork -mno-thumb -marm


5、 android2.3版本的 android_native_window_t 结构变更
typedef struct ANativeWindow android_native_window_t;
所以struct android_native_window_t --> android_native_window_t 变更即可
而2.2没有定义ANativeWindow结构

6、加入如下语句
ifdef FIXED_ARCH_TYPE
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/preprocessor/$(FIXED_ARCH_TYPE)/libglslPreprocessor.a)
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/compiler/$(FIXED_ARCH_TYPE)/libglslCompiler.a)
$(call add-prebuilt-files, STATIC_LIBRARIES, $(GC_GLESv2SC_DIR)/entry/$(FIXED_ARCH_TYPE)/libGLESv2SC.a)
endif

编译报找不到LOCAL_MODULE_TAGS定义,解决方法:
add-prebuilt-files的定义是在build/core/definitions.mk下,在include-prebuilt定义加入


define include-prebuilt
    include $$(CLEAR_VARS)
...
    LOCAL_MODULE_TAGS := eng  (增加此句即可)
    include $$(BUILD_PREBUILT)

endef


你可能感兴趣的:(Android系统框架学习,android,学习及系统开发)