Adding custom return type for marshalling/unmarshalling the data type in AIDL:
In Android application, while working with AIDL, I faced this problem.
If I am going to return any custom datatype or class in interface's functions, then we need to write .aidl and .java file.
For example from my AIDL interface function, I am going to return Rect custom class. Then I have to do the following:
Rect.aidl:
=========
package android.graphics;
// Declare Rect so AIDL can find it and knows that it implements
// the parcelable protocol.
parcelable Rect;
Rect.java
==============
import android.os.Parcel;
import android.os.Parcelable;
public final class Rect implements Parcelable {
public int left;
public int top;
public int right;
public int bottom;
public static final Parcelable.Creator<Rect> CREATOR = new
Parcelable.Creator<Rect>() {
public Rect createFromParcel(Parcel in) {
return new Rect(in);
}
public Rect[] newArray(int size) {
return new Rect[size];
}
};
public Rect() {
}
private Rect(Parcel in) {
readFromParcel(in);
}
public void writeToParcel(Parcel out) {
out.writeInt(left);
out.writeInt(top);
out.writeInt(right);
out.writeInt(bottom);
}
public void readFromParcel(Parcel in) {
left = in.readInt();
top = in.readInt();
right = in.readInt();
bottom = in.readInt();
}
}
I have to include this Rect.java in android compilation make file [make];
we should not include the .aidl file in Android.mk for this scenario.
This can happen when we are using NDK compilation. In NDK case, we will include java/include files in Android.mk.
Error:
* in my Android.mk file, I have added:
LOCAL_SRC_FILES += \
src/com/mycompany/mypackage/Rect.aidl \
But when we compile we will
Aidl: Test <= src/com/mycompany/mypackage//Rect.aidl
src/com/mycompany/mypackage/Rect.aidl:19 aidl can only generate
code for interfaces, not parcelables,
src/com/mycompany/mypackage/Rect.aidl:19 .aidl files that only
declare parcelables don't need to go in the Makefile.
In Android application, while working with AIDL, I faced this problem.
If I am going to return any custom datatype or class in interface's functions, then we need to write .aidl and .java file.
For example from my AIDL interface function, I am going to return Rect custom class. Then I have to do the following:
Rect.aidl:
=========
package android.graphics;
// Declare Rect so AIDL can find it and knows that it implements
// the parcelable protocol.
parcelable Rect;
Rect.java
==============
import android.os.Parcel;
import android.os.Parcelable;
public final class Rect implements Parcelable {
public int left;
public int top;
public int right;
public int bottom;
public static final Parcelable.Creator<Rect> CREATOR = new
Parcelable.Creator<Rect>() {
public Rect createFromParcel(Parcel in) {
return new Rect(in);
}
public Rect[] newArray(int size) {
return new Rect[size];
}
};
public Rect() {
}
private Rect(Parcel in) {
readFromParcel(in);
}
public void writeToParcel(Parcel out) {
out.writeInt(left);
out.writeInt(top);
out.writeInt(right);
out.writeInt(bottom);
}
public void readFromParcel(Parcel in) {
left = in.readInt();
top = in.readInt();
right = in.readInt();
bottom = in.readInt();
}
}
I have to include this Rect.java in android compilation make file [make];
we should not include the .aidl file in Android.mk for this scenario.
This can happen when we are using NDK compilation. In NDK case, we will include java/include files in Android.mk.
Error:
* in my Android.mk file, I have added:
LOCAL_SRC_FILES += \
src/com/mycompany/mypackage/Rect.aidl \
But when we compile we will
Aidl: Test <= src/com/mycompany/mypackage//Rect.aidl
src/com/mycompany/mypackage/Rect.aidl:19 aidl can only generate
code for interfaces, not parcelables,
src/com/mycompany/mypackage/Rect.aidl:19 .aidl files that only
declare parcelables don't need to go in the Makefile.
Labels: AIDL, android, application
