AIDL 编译报couldn't find import for class原因探究
来源:互联网 发布:python 开源项目 编辑:程序博客网 时间:2024/04/27 16:33
有如下AIDL代码:
package android.hardware;
import android.content.Context;
/**
* {@hide}
*/
interface IEinkctlService
{
boolean updateModeLock(boolean acquired, Context context);
int retrieveWorkMode();
boolean switchWorkMode(int mode);
}
编译时总是提示couldn't find import for class android.content.Context
似乎是找不到Context类,而实际上我们都知道android.content.Context确实是存在的。
上网搜寻一番,发现遇到此问题的人不少。
其实,要明白这个问题需要先搞清楚什么样的类是需要且可以import进AIDL中的。
参考《Android/OPhone开发完全讲义》第8章里的一段叙述:
“AIDL服务只支持有限的数据类型,因此,如果用AIDL服务传递一些复杂的数据就需要做更一步处理。AIDL服务支持的数据类型如下:
Java的简单类型(int、char、boolean等)。不需要导入(import)。
String和CharSequence。不需要导入(import)。
List和Map。但要注意,List和Map对象的元素类型必须是AIDL服务支持的数据类型。不需要导入(import)。
AIDL自动生成的接口。需要导入(import)。
实现android.os.Parcelable接口的类。需要导入(import)。
其中后两种数据类型需要使用import进行导入,将在本章的后面详细介绍。
传递不需要import的数据类型的值的方式相同。传递一个需要import的数据类型的值(例如,实现android.os.Parcelable接口的类)的步骤略显复杂。除了要建立一个实现android.os.Parcelable接口的类外,还需要为这个类单独建立一个aidl文件,并使用parcelable关键字进行定义。”
到此应该很清楚了,Context类并不是一个实现了Parcelable接口的类,也没有对应的AIDL文件,因此不能够在AIDL中import。
补充一句,网上有一种“办法”,说是在frameworks/base/Android.mk中的LOCAL_AIDL_INCLUDES := $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)前加上LOCAL_AIDL_INCLUDES := 欲import的类所在位置。其实这种“办法”也是受上面所说的import规则限制的。一个没有实现Parcelable接口的类,这种“办法”也是无能为力的。
- AIDL 编译报couldn't find import for class原因探究
- AIDL 编译报couldn't find import for class原因探究
- AIDL 编译报couldn't find import for class原因探究 .
- AIDL 编译报couldn't find import for class原因探究
- AIDL 编译报couldn't find import for class原因探究
- AIDL 编译报couldn't find import for class原因探究
- AIDL 编译报couldn't find import for class 解决方法
- Android aidl 编译报couldn't find import for class
- Android aidl 编译报couldn't find import for class
- Android aidl 编译错误:couldn't find import for class
- 在Eclipse编译aidl文件中出现couldn't find import for class原因
- 在Eclipse编译aidl文件中出现couldn't find import for class原因
- 在Eclipse编译aidl文件中出现couldn't find import for class原因
- 在Eclipse编译aidl文件中出现couldn't find import for class原因
- Android AIDL编译报couldn't find import for class android.content.Intent
- Android中AIDL 编译报couldn't find import for class解决办法
- Eclipse编译AIDL报错couldn't find import for class
- AIDL couldn't find import for class
- border-radius
- MessageFormat妙用
- jQuery 教程:简单的遮罩弹窗效果
- LeetCode - Validate Binary Search Tree
- 开源推荐系统
- AIDL 编译报couldn't find import for class原因探究
- 学习android JNI的那些事儿--------1. 搭建环境
- jetty服务器下对jstl的校验严格导致的运算不明确造成页面不能显示
- KMP算法——字符串匹配问题
- C# 第一次作业
- 一些android积累
- 电子书下载:Delphi 6 开发人员指南
- Android初级教程_onKeyDown监听返回键无效
- Android中使用ormlite实现持久化--HelloOrmLite