Android R系统aidl文件怎么对应的java文件找不到了?

    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_DIR
   Checkes 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=DIR
          Use DIR as a search path for import statements.
  -m FILE, --import=FILE
          Import FILE directly without searching in the search paths.
  -p FILE, --preprocessed=FILE
          Include FILE which is created by --preprocess.
  -d FILE, --dep=FILE
          Generate dependency file as FILE. Don't use this when
          there are multiple input files. Use -a then.
  -o DIR, --out=DIR
          Use DIR as the base output directory for generated files.
  -h DIR, --header_out=DIR
          Generate C++ headers under DIR.
  -a
          Generate dependency file next to the output file with the
          name based on the input file.
  -b
          Trigger fail when trying to compile a parcelable.
  --ninja
          Generate dependency file in a format ninja understands.
  --structured
          Whether this interface is defined exclusively in AIDL.
          It is therefore a candidate for stabilization.
  --stability=<level>
          The stability requirement of this interface.
  -t, --trace
          Include tracing code for systrace. Note that if either
          the client or service code is not auto-generated by this
          tool, that part will not be traced.
  --transaction_names
          Generate transaction names.
  --apimapping
          Generates a mapping of declared aidl method signatures to
          the 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,|void
              foo/bar/IFoo.aidl:39
  -v VER, --version=VER
          Set the version of the interface and parcelable to VER.
          VER must be an interger greater than 0.
  --hash=HASH
          Set the interface hash to HASH.
  --log
          Information about the transaction, e.g., method name, argument
          values, execution time, etc., is provided via callback.
  --parcelable-to-string
          Generates an implementation of toString() for Java parcelables,
          and ostream& operator << for C++ parcelables.
  --help
          Show 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 are
  more than one.
  For Java, if omitted, Java source file is generated at the same
  place 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文件就到这里了。总之,青山不改绿水长流先到这里了。如果本博客对你有所帮助,麻烦关注或者点个赞,如果觉得很烂也可以踩一脚!谢谢各位了!!

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值