android aidl 命令

关键字:Android, aidl

20180903 tjy

转载请注明出处

aidl是android中的binder通信的重要的一个内容。它把*.aidl文件转换成java或者cpp文件,然后生成的java或者cpp文件参与编译,可以实现ibiner机制。

这里只介绍下使用aidl转换aidl文件到java文件的方法。

aidl可执行文件在android源码中的位置:

prebuilts/sdk/tools/{platform}/bin/aidl
platform可以是linux/darwin/windows/
比如,prebuilts/sdk/tools/linux/bin/aidl

aidl的使用方法:

john@john-ThinkPad-Edge-E435:~/workspace/android/android-source-code$ ./prebuilts/sdk/tools/linux/bin/aidl
INPUT required
usage: aidl OPTIONS INPUT [OUTPUT]
       aidl --preprocess OUTPUT INPUT...

OPTIONS:
   -I    search path for import statements.
   -d   generate dependency file.
   -a         generate dependency file next to the output file with the name based on the input file.
   -ninja     generate dependency file in a format ninja understands.
   -p   file created by --preprocess to import.
   -o base output folder for generated files.
   -b         fail when trying to compile a parcelable.

INPUT:
   An aidl interface file.

OUTPUT:
   The generated interface files.
   If omitted and the -o option is not used, the input filename is used, with the .aidl extension changed to a .java extension.
   If the -o option is used, the generated files will be placed in the base output folder, under their package folder

用ILocationManager.aidl举例,在android源码根目录,命令如下:

./prebuilts/sdk/tools/linux/bin/aidl \
-Iframeworks/base/core/java/ \
-Iframeworks/base/location/java/ \
-Iframeworks/base/core/java/ \
-Iframeworks/base/location/java/ \
-oaidl-out \
frameworks/base/location/java/android/location/ILocationManager.aidl

生成的文件为:

john@john-ThinkPad-Edge-E435:~/workspace/android/android-source-code/aidl-out$ tree
.
└── android
    └── location
        └── ILocationManager.java

aidl在android源码中是有源码的,在 system/tools/aidl/,在使用aidl可执行文件遇到问题了或者对aidl源码感兴趣,可以读下。

john@john-ThinkPad-Edge-E435:~/workspace/android/android-source-code/system/tools/aidl$ tree -L 1
.
├── aidl.cpp
├── aidl.h
├── aidl_language.cpp
├── aidl_language.h
├── aidl_language_l.ll
├── aidl_language_y.yy
├── aidl_unittest.cpp
├── Android.bp
├── Android.mk
├── ast_cpp.cpp
├── ast_cpp.h
├── ast_cpp_unittest.cpp
├── ast_java.cpp
├── ast_java.h
├── ast_java_unittest.cpp
├── code_writer.cpp
├── code_writer.h
├── docs
├── generate_cpp.cpp
├── generate_cpp.h
├── generate_cpp_unittest.cpp
├── generate_java_binder.cpp
├── generate_java.cpp
├── generate_java.h
├── import_resolver.cpp
├── import_resolver.h
├── io_delegate.cpp
├── io_delegate.h
├── io_delegate_unittest.cpp
├── line_reader.cpp
├── line_reader.h
├── logging.h
├── main_cpp.cpp
├── main_java.cpp
├── MODULE_LICENSE_APACHE2
├── NOTICE
├── options.cpp
├── options.h
├── options_unittest.cpp
├── os.h
├── OWNERS
├── runtests.sh
├── tests
├── type_cpp.cpp
├── type_cpp.h
├── type_cpp_unittest.cpp
├── type_java.cpp
├── type_java.h
├── type_java_unittest.cpp
├── type_namespace.cpp
└── type_namespace.h

你可能感兴趣的:(android aidl 命令)