android 新增native binder service 方式(二)

接上篇文章,实现binder service 的第二种方式,这种在系统里面比较常见

先看下整体目录结构,整体差别不大。

一 android.bp 编译aidl 文件

aidl_interface {
    name: "libserviceaidl",
    srcs: [
        "aidl/com/test/IService.aidl",
        "aidl/com/test/IServiceCallback.aidl",
    ],
    include_dirs: ["aidl"],
    local_include_dir: "aidl",
    backend: {
        cpp: {
            enabled: true,
        },
    },
    versions: [
        "1",
    ],
}

make libserviceaidl 

会报一系列错误,按照报错处理就可以了。

报错处理:

FAILED: out/soong/.intermediates/vendor/qcom/proprietary/testserver/libserviceaidl/libserviceaidl-api/checkapi_current.timestamp
echo "API dump for the current version of AIDL interface libserviceaidl does not exist." && echo Run "m libserviceaidl-update-api", or add "unstable: true" to the build rule for the interface if it does not need to be versioned && false
API dump for the current version of AIDL interface libserviceaidl does not exist.
Run m libserviceaidl-update-api, or add unstable: true to the build rule for the interface if it does not need to be versioned

执行 m libserviceaidl-update-api

[100% 352/352] //vendor/qcom/proprietary/testserver/libserviceaidl:libserviceaidl-api Making AIDL API of libserviceaidl as version current
FAILED: out/soong/.intermediates/vendor/qcom/proprietary/testserver/libserviceaidl/libserviceaidl-api/updateapi_current.timestamp
echo "module libserviceaidl-api missing dependencies: vendor/qcom/proprietary/testserver/libserviceaidl/aidl_api/libserviceaidl/1" && false
module libserviceaidl-api missing dependencies: vendor/qcom/proprietary/testserver/libserviceaidl/aidl_api/libserviceaidl/1
17:33:18 ninja failed with: exit status 1

按照提示 libserviceaidl/aidl_api/libserviceaidl/1,新建各级目录,缺少加啥,然后把aidl 文件放进去

###############################################################################
# ERROR: Backward incompatible change detected on AIDL API                    #
###############################################################################
Above AIDL file(s) has changed in a backward-incompatible way, e.g. removing
a method from an interface or a field from a parcelable. If a device is shipped
with this change by ignoring this message, it has a high risk of breaking later
when a module using the interface is updated, e.g., Maineline modules.
17:41:40 ninja failed with: exit status 1
 

把current 生成的文件放到 version 1的目录,覆盖掉,保持一致就可以了。

编译成功会生成ystem/lib/libserviceaidl-V1-cpp.so  ,push 到system/lib/下

二,编译Native service 和 client

cc_binary {
    name: "testservverfirst",
    srcs: ["servertest.cpp",
           ],
    shared_libs: [
        "liblog",
        "libcutils",
        "libutils",
        "libbinder",
        "libserviceaidl-cpp", 
    ],

    init_rc: ["testservver.rc"],
}


cc_binary {
    name: "clienttest",
        srcs: ["clienttest.cpp", 
          ],

    shared_libs: [
        "liblog",
        "libcutils",
        "libutils",
        "libbinder",
        "libserviceaidl-cpp", 
    ],
}

调用方式和前面文章一致,添加selinux 权限也一样。
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值