当前位置: 首页 > article >正文

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


http://www.kler.cn/a/561369.html

相关文章:

  • 游戏引擎学习第121天
  • 解决npm/yarn等包管理工具在vscode中使用出现系统禁止运行脚本的情况
  • python学智能算法(五)|差分进化算法:原理认识和极小值分析
  • 深度学习c++资源库:vector容器,蓝桥杯常用算法sort,unique(排序+去重)
  • Linux运维——网络管理
  • [021-22].Redis的线程模型原理分析
  • self-attention部分代码注释
  • 清华大学DeepSeek文档下载,清华大学deepseek下载(完成版下载)
  • 在WINDOWS系统使用CMake gui编译NLopt配合VSCode使用
  • java项目之网络游戏交易系统源码(ssm+mysql)
  • 结构型模式 - 外观模式 (Facade)
  • 计算机毕业设计SpringBoot+Vue.js教学资源库(源码+文档+PPT+讲解)
  • labview实现有符号位16进制转二进制补码转真值
  • 每日一题-设计内存分配器;详细分析思路以及多解法
  • 企业业务安全进阶之路:AI技术与数据分析的应用
  • JavaWeb 学习笔记
  • 个人电脑小参数GPT预训练、SFT、RLHF、蒸馏、CoT、Lora过程实践——MiniMind图文版教程
  • linux--多进程开发基础(3) exec函数族
  • JavaWeb-GenericServlet源码分析(适配器/模板方法)
  • Sui 通过 SCION 推进网络安全与性能