Search code examples
androidaidl

Can't use custom classes in aidl


I have two applications which communicate via aidl interface. Everything works when I use basic types like String or int, however according to this I should be able to use custom types too. However code (even very simplified) doesn't compile in my case.

This is how it looks like:

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;

At this point code compiles but when in some other class I just do:

import edu.cat.ion.TestClass;

I get:

error: cannot find symbol

import edu.cat.ion.TestClass;

Do you know what can be wrong?


Solution

  • You are seeing the error because of path mismatch for TestClass.java file.

    Currently your TestClass.java is located under aidl folder which other java classes are not able to find.

    Hence move your

    app/src/main/aidl/edu/cat/ion/TestClass.java

    file to java folder.

    app/src/main/java/edu/cat/ion/TestClass.java