如何做好网站的优化/推广下载
Android R系统aidl文件怎么对应的java文件找不到了?
引言
Android系列博客沉寂很久了,很久了!不是我已经离开了江湖,而是最近忙着给OpenHarmony鸿蒙小系统,标准系统而给耽误了。这不趁着这两天有点空闲时间,准备调试下Android,可是尼玛确突然发现Android的系统aidl文件转换生成的java文件一直找到不,我find,grep找了个寂寞怎么也找不到。突然有点怀疑自我了,我是谁我在那里,这是怎么了。这才有了今天的博客。
原来在Android R上面新增加了一套机制,对于R publice类型的aidl文件生成的java文件的目录会自动编译出来生成在如下的目录:
out/soong/.intermediates
而对于Android R中如果aidl文件被标记为hide,则需要通过aidl命令,手动转换aidl文件到java文件。所以我前面怎么倒腾也就找不到了(因为我要找的aidl文件恰好被定义成为hidl类型的了)。
其实对于上面的这种hidl文件生成对应的java有一种更加简单的方法,就是直接把hidl暂时删除,然后重新编译即可。
一.aidl命令的使用
对于实战类型的博客,我们不来虚的,必须真刀真枪的实干才可以。我们直接来看看要怎么使用功能aidl命令将aidl文件转换成java文件!
1.1 构建Android编译环境
这个吗地球人懂的都懂,不懂的也木有办法了。
#source source build/envsetup.sh
#lunch xxxx
#make aidl
1.2 了解aidl命令
老规矩,在使用一个命令之前,我们有必要了解一下它!通常的一个好的命令通常会提供说明使用的命令,它肯定也不例外,我们可以在终端下输入aidl或者aidl --help
tangkw@dell-PowerEdge-R740xd:~/android_source/aosp$ aidl --help
usage:
aidl --lang={java|cpp|ndk} [OPTION]... INPUT...Generate Java or C++ files for AIDL file(s).aidl --preprocess OUTPUT INPUT...Create an AIDL file having declarations of AIDL file(s).aidl --dumpapi --out=DIR INPUT...Dump API signature of AIDL file(s) to DIR.aidl --checkapi OLD_DIR NEW_DIRCheckes whether API dump NEW_DIR is backwards compatible extension of the API dump OLD_DIR.aidl [OPTION]... INPUT [OUTPUT]Generate a Java file for an AIDL file.OPTION:-I DIR, --include=DIRUse DIR as a search path for import statements.-m FILE, --import=FILEImport FILE directly without searching in the search paths.-p FILE, --preprocessed=FILEInclude FILE which is created by --preprocess.-d FILE, --dep=FILEGenerate dependency file as FILE. Don't use this whenthere are multiple input files. Use -a then.-o DIR, --out=DIRUse DIR as the base output directory for generated files.-h DIR, --header_out=DIRGenerate C++ headers under DIR.-aGenerate dependency file next to the output file with thename based on the input file.-bTrigger fail when trying to compile a parcelable.--ninjaGenerate dependency file in a format ninja understands.--structuredWhether this interface is defined exclusively in AIDL.It is therefore a candidate for stabilization.--stability=<level>The stability requirement of this interface.-t, --traceInclude tracing code for systrace. Note that if eitherthe client or service code is not auto-generated by thistool, that part will not be traced.--transaction_namesGenerate transaction names.--apimappingGenerates a mapping of declared aidl method signatures tothe original line number. e.g.: If line 39 of foo/bar/IFoo.aidl contains: void doFoo(int bar, String baz);Then the result would be:foo.bar.Baz|doFoo|int,String,|voidfoo/bar/IFoo.aidl:39-v VER, --version=VERSet the version of the interface and parcelable to VER.VER must be an interger greater than 0.--hash=HASHSet the interface hash to HASH.--logInformation about the transaction, e.g., method name, argumentvalues, execution time, etc., is provided via callback.--parcelable-to-stringGenerates an implementation of toString() for Java parcelables,and ostream& operator << for C++ parcelables.--helpShow this help.INPUT:An AIDL file.OUTPUT:Path to the generated Java or C++ source file. This is ignored when-o or --out is specified or the number of the input files aremore than one.For Java, if omitted, Java source file is generated at the sameplace as the input AIDL file,HEADER_DIR:Path to where C++ headers are generated.
其中上述命令最最重要的两个参数就是-I和-p,这里我们重点说一下它两:
-
-I:输入我们要转换的aidl文件中import的aidl文件的路径,譬如我们定义了一个ATEST.aidl文件,如下:
package android.view; import android.view.SurfaceControl;/*** System private per-application interface to the window manager.** {@hide}*/ interface ATEST { }
import的frameworks/base/core/java/android/view/SurfaceControl.aidl,所以此时的-I参数一定指定为./frameworks/base/core/java,否则会提示如下的错误码:
ERROR: android.view.SurfaceControl: couldn't find import for class android.view.SurfaceControl
-
-p 接的是预处理文件framework.aidl
-
重要的事情说三遍-I ,-p等后不接空格 直接跟参数,不要空格,不要空格!
1.3 使用aidl命令
这里我们准备生成IWindowSession.aidl对应的java文件,其具体的命令如下:
tangkw@dell-PowerEdge-R740xd:~/android_source/aosp$ aidl -I./frameworks/base/core/java -p./prebuilts/sdk/current/public/framework.aidl ./frameworks/base/core/java/android/view/IWindowSession.aidl
没有输出结果,因为这里没有指定输出目录,所以它会在aidl同级目录生成对应的java文件,如下:
tangkw@dell-PowerEdge-R740xd:~/android_source/aosp$ ls ./frameworks/base/core/java/android/view/IWindowSession.java
./frameworks/base/core/java/android/view/IWindowSession.java
写在最后
好了,打卡收工下班。今天的博客Android R系统aidl文件怎么转换成java文件就到这里了。总之,青山不改绿水长流先到这里了。如果本博客对你有所帮助,麻烦关注或者点个赞,如果觉得很烂也可以踩一脚!谢谢各位了!!