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 权限也一样。