一 Ubuntu系统搭建aidl 生成环境
1.1 使用Android SDK包
build-tools-3400.tar
1.2 从android 编译目录取
1.2.1 android 中生成的地方,可以看具体的生成逻辑
/system/tools/aidl/Android.bp
118 // aidl executable
119 cc_binary_host {
120 name: "aidl",
121 defaults: ["aidl_defaults"],
122 srcs: ["main.cpp"],
123 static_libs: [
124 "libaidl-common",
125 "libbase",
126 "liblog",
127 ],
128 }
129
130 // aidl-cpp legacy executable, please use 'aidl' instead
131 cc_binary_host {
132 name: "aidl-cpp",
133 defaults: ["aidl_defaults"],
134 srcs: ["main.cpp"],
135 cflags: ["-DAIDL_CPP_BUILD"],
136 static_libs: [
137 "libaidl-common",
138 "libbase",
139 "liblog",
140 ],
141 }
1.2.2 生成的目录
/alps/xxx/soong/.intermediates/system/tools/aidl$ ls -al
total 20
drwxrwxr-x 5 fred fred 4096 Mar 4 19:28 .
drwxrwxr-x 7 fred fred 4096 Mar 5 09:23 ..
drwxrwxr-x 3 fred fred 4096 Mar 4 19:25 aidl
drwxrwxr-x 3 fred fred 4096 Mar 4 19:25 aidl-cpp
drwxrwxr-x 3 fred fred 4096 Mar 4 19:28 libaidl-common
1.2.3 aidl 抽离到ubutun系统
将上面的aidl bin文件copy到ubuntu的/usr/lib/x86_64-linux-gnu
然后 ldd aidl
fred@fred:~/Desktop$ ldd aidl
linux-vdso.so.1 (0x00007fff7a34c000)
libc++.so => not found
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa2cf63d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2cf61a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa2cf4cb000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa2cf4c1000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa2cf4a6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2cf2b2000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2cf929000)
解决办法:https://blog.csdn.net/qq_21920075/article/details/126750473
从Android 编译出来的out目录找到libc++.so
find . -name libc++.so*
cp ./host/linux-x86/lib64/libc++.so ~/Desktop/
sudo cp libc++.so /usr/lib/x86_64-linux-gnu/
sudo cp libc++.so /lib/x86_64-linux-gnu/
1.3 实际操作(传递自定义数据类型)
1.3.1 aidl 文件内容
IRmAudioFocus.aidl
// IRmAudioFocus
package vendor.remote.rm_audiofocus;
import vendor.remote.rm_audiofocus.IRmAudioFocusCallback;
import vendor.remote.rm_audiofocus.RmAudioFocusInfo;
interface IRmAudioFocus {
void setAudioFocusCallback( in @nullable IRmAudioFocusCallback callback, in int id);
int requestAudioFocus(in RmAudioFocusInfo audioFocusInfo, in int id);
int abandonAudioFocus(in RmAudioFocusInfo audioFocusInfo, in int id);
}
IRmAudioFocusCallback.aidl
package vendor.remote.rm_audiofocus;
import vendor.remote.rm_audiofocus.RmAudioFocusInfo;
oneway interface IRmAudioFocusCallback {
void notifyAudioFocusRequest(in RmAudioFocusInfo afi, in int id);
void notifyAudioFocusAbandon(in RmAudioFocusInfo afi, in int id);
// callback for volume events
void notifyVolumeAdjust(int adjustment, in int id);
}
RmAudioFocusInfo.aidl
// RmAudioFocusInfo.aidl
package vendor.remote.rm_audiofocus;
import vendor.remote.rm_audiofocus.RmAudioAttributes;
// ref AudioFocusInfo.java and AudioAttributes.java
parcelable RmAudioFocusInfo {
RmAudioAttributes attributes;
int clientUid;
String clientId;
String packageName;
int sdkTarget;
int gainRequest;
int loosReceived;
int flags;
long genCount;
int vsockCid;
int notifyTop;
}
RmAudioAttributes.aidl
package vendor.remote.rm_audiofocus;
// ref AudioAttributes.java
parcelable RmAudioAttributes {
int usage;
int contentType;
int source;
int flags;
}
1.3.2 生成Bn/Bp接口类的命令
aidl --lang=cpp -I ./ -h ../interface_cpp/include -o ../interface_cpp vendor/remote/rm_audiofocus/*.aidl
1.3.3 最终生成的目录结构
~/Desktop/aidl_demo$ tree
.
├── aidl_demo
│ └── vendor
│ └── remote
│ └── rm_audiofocus
│ ├── IRmAudioFocus.aidl
│ ├── IRmAudioFocusCallback.aidl
│ ├── RmAudioAttributes.aidl
│ └── RmAudioFocusInfo.aidl
└── interface_cpp
├── include
│ └── vendor
│ └── remote
│ └── rm_audiofocus
│ ├── BnRmAudioAttributes.h
│ ├── BnRmAudioFocusCallback.h
│ ├── BnRmAudioFocus.h
│ ├── BnRmAudioFocusInfo.h
│ ├── BpRmAudioAttributes.h
│ ├── BpRmAudioFocusCallback.h
│ ├── BpRmAudioFocus.h
│ ├── BpRmAudioFocusInfo.h
│ ├── IRmAudioFocusCallback.h
│ ├── IRmAudioFocus.h
│ ├── RmAudioAttributes.h
│ └── RmAudioFocusInfo.h
└── vendor
└── remote
└── rm_audiofocus
├── IRmAudioFocusCallback.cpp
├── IRmAudioFocus.cpp
├── RmAudioAttributes.cpp
└── RmAudioFocusInfo.cpp
12 directories, 20 files