最近的时候我需要引用其他人的aidl文件到项目里面,引入的时候发现android studio无法生成对应的java类,但是用android studio新建的aidl却可以,这就令人奇怪了,我在网络上查找了好久的信息,很多都没有解决,直到后来找到了问题。
// IStateLamp.aidl
package com.sunmi.statuslampmanager;
// Declare any non-default types here with import statements
import java.lang.String;
interface IStateLamp {
/**
* 功能:控制单个报警灯
* 参数:
* [in]status 状态,0亮,1灭
* [in]lamp Led灯,参数:
* "Led-1"
* "Led-2"
* "Led-3"
* "Led-4"
* "Led-5"
* "Led-6"
* 返回值:无
*/
void controlLamp(in int status, in String lamp);
/**
* 功能:控制单个报警灯循环 显示
* 参数:
* [in]status 状态,0开始循环,1停止循环
* [in]lightTime 报警灯亮时间,单位:毫秒(ms)
* [in]putoutTime 报警灯灭时间,单位:毫秒(ms)
* [in]lamp Led灯,参数:
* "Led-1"
* "Led-2"
* "Led-3"
* "Led-4"
* "Led-5"
* "Led-6"
* 返回值:无
*/
void controlLampForLoop(in int status, in long lightTime, in long putoutTime, in String lamp);
/**
* 功能:关闭所有报警灯
*/
void closeAllLamp();
}
这个aidl本身看起来没有很大的差别,但是就是无法生成对应的java类,是一个空的java文件。
后来修改了文件一下内容
// IStateLamp.aidl
package com.sunmi.statuslampmanager;
// Declare any non-default types here with import statements
import java.lang.String;
interface IStateLamp {
void controlLamp(in int status, in String lamp);
void controlLampForLoop(in int status, in long lightTime, in long putoutTime, in String lamp);
void closeAllLamp();
}
就是把里面的中文注释删除后你就会发现可以正常生成对应文件,就是文件里面如果有中文其他不是英文的字符就会导致无法生成,或者就是ide里面那个地方编码有问题导致无法正确读取里面的中文。