Java和C ++之间的AIDL接口 [英] AIDL interface between Java and C++

查看:454
本文介绍了Java和C ++之间的AIDL接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AIDL界面的新手.我想在使用gradle构建的Java(应用程序层)和使用cmake构建的C ++(本机层)之间实现AIDL接口.我需要使用AIDL接口在这两个进程之间传递大量数据.我能够在应用程序层中实现.aidl文件,并能够创建服务.我需要在本机层中实现一个辅助客户端,并需要传递数据.谁能建议我如何实现将要构建的cmake AIDL.

I am a new to AIDL interface. I would like to implement AIDL interface between Java(Application layer) which is build using gradle and C++(Native layer) which is build using cmake. I need to pass a chunk of data between these two processes using AIDL interface. I am able to implement a .aidl file in application layer and able to create a service. I need to implement a aidl client in native layer and need to pass data. Can anyone suggest me how to implement AIDL which is to be build cmake.

推荐答案

要获取 aidl-cpp 二进制文件,您必须使用此处和前几条说明此处.一旦设置了构建环境,就可以使用 make aidl-cpp 来构建二进制文件.然后可以找到二进制文件在 out/host/linux-x86/bin/aidl-cpp 中.获得二进制文件后,您只需要执行一次即可.您不再需要AOSP代码(尽管可以使用该代码可以快速搜索示例).

To obtain the aidl-cpp binary, you would have to set up the AOSP source code using the instructions here and the first few instructions here. Once you have set up the build environment, you can build the binary with make aidl-cpp. The binary can then be found e.g. in out/host/linux-x86/bin/aidl-cpp. You only have to do this once, after you have obtained the binary you no longer need the AOSP code (though it is nice to have the code around to quickly search for examples).

关于CMake的部分,如注释中所述,一旦构建了 aidl-cpp 二进制文件,就可以使用CMake命令

Regarding the CMake part, as discussed in the comment, once you have build the aidl-cpp binary, you can use the CMake command add_custom_target for code generation.

aidl-cpp 命令提供以下说明:

usage: aidl-cpp INPUT_FILE HEADER_DIR OUTPUT_FILE

OPTIONS:
   -I<DIR>   search path for import statements
   -d<FILE>  generate dependency file
   -ninja    generate dependency file in a format ninja understands

INPUT_FILE:
   an aidl interface file
HEADER_DIR:
   empty directory to put generated headers
OUTPUT_FILE:
   path to write generated .cpp code

因此,当您从cmake调用命令时,必须提供AIDL,然后提供一个目录,在其中应存储生成的头文件,并在其下存储生成的cpp文件的名称.例如. aidl-cpp ISomeInterface.aidl ./generate-headers ./generated-cpp/ISomeInterface.cpp .如果要使用自定义数据类型(请参见此答案的最后一部分),则还必须传递 -I 标志以指向自定义数据类型的声明.

So when you call the command from cmake, you would have to provide your AIDL, then a directory in which the generated header files should be stored, and the name under which the generated cpp file should be stored. E.g. aidl-cpp ISomeInterface.aidl ./generated-headers ./generated-cpp/ISomeInterface.cpp. If you want to use a custom data type (see the last section of this answer), you would also have to pass the -I flag to point to the declaration of your custom data types.

使用 aidl-cpp 生成头文件和cpp文件后,即可从C ++连接到服务.这是来自AOSP源代码的示例:

Once you have generated the header files and the cpp file with aidl-cpp, you can then connect to your service from C++. Here is an example from the AOSP source code:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆