Android studio 使用AIDL 无法import class问题解决

来源:互联网 发布:matlab矩阵绝对值 编辑:程序博客网 时间:2024/04/30 10:28

在用android studio 用AIDL的过程中,AIDL默认支持的数据类型如下(来自android文档):

By default, AIDL supports the following data types:

  • All primitive types in the Java programming language (such as int,long,char, boolean, and so on)
  • String
  • CharSequence
  • List

    All elements in the List must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared. A List may optionally be used as a "generic" class (for example,List<String>). The actual concrete class that the other side receives is always an ArrayList, although the method is generated to use theList interface.

  • Map

    All elements in the Map must be one of the supported data types in this list or one of the other AIDL-generated interfaces or parcelables you've declared.  Generic maps, (such as those of the formMap<String,Integer> are not supported. The actual concrete class that the other side receives is always aHashMap, although the method is generated to use theMap interface.

You must include an import statement for each additional type not listed above, even if they are defined in the same package as your interface.

如果不是AIDL数据类型,需要自己定义一个新的AIDL文件并实现parcelable接口,示例如下:

 

For example, here is a Rect.aidl file to create a Rect class that's parcelable:

package android.graphics;// Declare Rect so AIDL can find it and knows that it implements// the parcelable protocol.parcelable Rect;

And here is an example of how the Rect class implements theParcelable protocol.

import android.os.Parcel;import android.os.Parcelable;public final class Rect implements Parcelable {

以上两步做完后并不能编译通过,在使用android studio的时候会有类似如下的错误

Error:(5) couldn't find import for class com.XXX.xxx

通过在在android-studio\sdk\platforms\android-19\framework.aidl添加如下内容解决

parcelable com.XXX.xxx;

 

0 0
原创粉丝点击