android - 不能在aidl中使用自定义类

标签 android aidl

我有两个应用程序通过 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/

相关文章:

android - Android 上的 WebView 动画问题

java - 通过邮寄方式将文件上传到服务器 OutOfMemory

Android NDK clang 编译器找不到 std::make_unique

android - 向 Android.mk 添加 aidl 文件

Android:两个独立APK的两个服务之间的通信

java - 如何在Eclipse中生成扩展名将.aidl更改为.java?

Android:计划重复的 TimerTask 仅被触发一次

java - android quiz 单选按钮不显示正确的值

android - 如何在我的应用程序中实现 AT 命令调用?