行业知识
Android 11 创建自定义AIDL HAL
2026-11-10 04:38:26
来源:互联网转载
背景
项目中需要在Android 11中自定义HAL,由于从Android 11开始,可以使用AIDL定义HAL,本文简单记录了AIDL的HAL创建方法。
- 注意:本文适用于Android 11,其他版本可能有不同的问题需要不同的解决方案。
步骤
1. 设置编译环境
source build/envsetup.shlunch aosp_trout_arm64-userdebug
2. 创建HAL目录
创建如下目录:
/hardware/interfaces/automotive/helloworld
- 注意:后续所有目录均为上面目录下的相对路径。
3. 创建AIDL
- 添加AIDL文件
aidl/android/hardware/automotive/helloworld/IHelloworld.aidl:
package android.hardware.automotive.helloworld;@VintfStabilityinterface IHelloworld {void sayHello(in String name);}- 添加 Android.bp
aidl/Android.bp:
aidl_interface { name: "android.hardware.automotive.helloworld", vendor_available: true, srcs: [ "android/hardware/automotive/helloworld/*.aidl", ], stability: "vintf", owner: "mycompany", backend: { java: { platform_apis: true, } }, versions: [],}- 注意: 将owner设置为组织名称。
Android.bp:
package { default_applicable_licenses: ["Android-Apache-2.0"],}cc_defaults { name: "HelloworldiHalInterfaceDefaults", static_libs: [ "android.hardware.automotive.helloworld-ndk_platform", ],}4. 生成 aidl_api
mm android.hardware.automotive.helloworld-update-api
此命令会生成如下目录结构:
aidl_api└── android.hardware.automotive.helloworld └── current └── android └── hardware └── automotive └── helloworld └── IHelloworld.aidl
- 注意: 如果Android.bp中未设置owner,此步骤会报如下错误:
TODO: 添加错误消息
随后运行
mm android.hardware.automotive.helloworld-freeze-api
此命令会添加如下目录结构:
aidl_api└── android.hardware.automotive.vapi └── 1 └── android └── hardware └── automotive └── vapi ├── IVapi.aidl ├── IVapiCallback.aidl └── StatusCode.aidl
Android.bp会被自动更新为:
aidl_interface { name: "android.hardware.automotive.helloworld", vendor_available: true, srcs: [ "android/hardware/automotive/helloworld/*.aidl", ], stability: "vintf", owner: "mycompany", backend: { java: { platform_apis: true, } }, versions: ["1"], //
- 注意: 如果Android.bp中未设置owner,此步骤会报如下错误:
- 注意: 将owner设置为组织名称。
- 添加 Android.bp
- 添加AIDL文件
- 注意:后续所有目录均为上面目录下的相对路径。