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

在用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). The actual concrete class that the other side receives is always an ArrayList, although the method is generated to use the List 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 are not supported. The actual concrete class that the other side receives is always a HashMap, although the method is generated to use the Map 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;

 

你可能感兴趣的:(Android,App开发)