Android AIDL import 错误

如果你在使用aidl接口过程中,生成aidl接口文件失败时(具体表现为:build目录下aidl的目录里,对应的aidl的接口文件打开是空白的),使用时可能是导致无法引用或找不到包时。你可以试试是否由于aidl的接口中有中文注释,可以去除或者修改为英语注释,然后clean 之后再make,此时很有可能就可以用了。  

如果你的aidl 接口中,参数或返回结果包含自定义的类结构,该自定义的类结构需要在 aidl中定义,并在aidl对应的包目录里定义该类结构,该类结构需要实现parcelable接口。在aidl中,定义结构为:parcelable 类名。举例如下:

aidl中的定义:

package com.test.aidl;


parcelable TestInfo;
package com.test.aidl;

import android.os.Parcel;
import android.os.Parcelable;


public class TestInfo implements Parcelable {

    private int type;

    private String name;

    
    
    public TestInfo () {

    }

    protected TestInfo (Parcel in) {
        type = in.readInt();
        name = in.readString();
    }

    public static final Creator<TestInfo > CREATOR = new Creator<TestInfo >() {
        @Override
        public TestInfo createFromParcel(Parcel in) {
            return new TestInfo (in);
        }

        @Override
        public TestInfo [] newArray(int size) {
            return new TestInfo [size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeString(name);
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


}

猜你喜欢

转载自blog.csdn.net/frj463806056/article/details/104773242
今日推荐