Android Studio, aidl refusing to generate code from aidl file defining parcelable. Why?

回调的对象 Test.java (Implements Parcelable):

package com.app.pack.classes;

public class Test implements Parcelable {

    private int test = 33;

    protected Test(Parcel in) {
        test = in.readInt();
    }

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

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

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

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

与回调对象同名的AIDL文件 Test.aidl (Declares the class I want to send):

package com.app.pack.aidl;
parcelable Test;

调用接口的AIDL文件 TestService.aidl (provides the method that returns a Test object):

package com.app.pack.aidl;
import com.app.pack.aidl.Test;

interface TestService{
Test getAll(in int[] listOfInts);
}

这样写编译会报错:
refusing to generate code from aidl file defining parcelable couldn’t find import for class xxxxx

原因:
回调的对象类 (Test.java)的包名 与 回调对象同名的AIDL文件(Test.aidl)的包名不一致会导致此问题,这两个文件(Test.java 和 Test.aidl)的包名必须一致
Test类的包名:com.app.pack.classes
Test.aidl 文件的包名:com.app.pack.aidl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值