我有两个应用程序通过 aidl 接口(interface)进行通信。当我使用像 String 或 int 这样的基本类型时一切正常,但是根据 this我也应该能够使用自定义类型。然而,在我的例子中,代码(即使非常简化)无法编译。
它是这样的:
app/src/main/aidl/edu/cat/ion/TestClass.java:
package edu.cat.ion;
import android.os.Parcel;
import android.os.Parcelable;
public final class TestClass implements Parcelable {
public TestClass() {
}
protected TestClass(Parcel in) {
}
public static final Creator<TestClass> CREATOR = new Creator<TestClass>() {
@Override
public TestClass createFromParcel(Parcel in) {
return new TestClass(in);
}
@Override
public TestClass[] newArray(int size) {
return new TestClass[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
app/src/main/aidl/edu/cat/ion/TestClass.aidl:
package edu.cat.ion;
parcelable TestClass;
此时代码可以编译,但是在其他一些类中我只是这样做:
import edu.cat.ion.TestClass;
我得到:
error: cannot find symbol
import edu.cat.ion.TestClass;
你知道什么是错误的吗?
最佳答案
您看到的错误是因为 TestClass.java
文件的路径不匹配。
目前您的 TestClass.java
位于 aidl
文件夹下,其他 java
类无法找到。
因此移动你的
app/src/main/aidl/edu/cat/ion/TestClass.java
文件到 java
文件夹。
app/src/main/java/edu/cat/ion/TestClass.java
关于android - 不能在aidl中使用自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52447210/