2

I have been trying to use IPCs for a multi-apk project.

One of them exposes a Service with quite a few methods. Some of those methods take Parcelable objects as parameters (or returns them).

The first thing I did was to create an aidl file for my Service.

Here's a small part of this aidl file:

package com.test.myapp;    
import com.test.mylib.Settings;

interface ISettingsService {
  boolean getSettings(in com.test.mylib.Settings arg1);
}

I use Android Studio and gradle, so I saved this aidl file in the src/main/aidl/com/test/myapp/ folder of my module.

As the Settings object is Parcelable, the Android documentation states that I also have to declare an aidl file for it. Note that the Settings class is in another package because it is defined in an included jar library that I cannot modify.

So I created the src/main/aidl/com/test/myapp/Settings.aidl file:

package com.test.mylib;

parcelable Settings;

At build time, the compiler should open my aidl files and generate the proper ISettingsService stub object that I can implement. The problem is that the compiler gives me this error :

error: cannot find symbol
_arg0 = com.test.mylib.Settings.CREATOR.createFromParcel(data);
                                      ^
symbol:   variable CREATOR
location: class Settings
/.../myapp/build/source/aidl/debug/com/test/myapp/ISettingsService.java:89: error: cannot find symbol
arg1.writeToParcel(_data, 0);
^
symbol:   method writeToParcel(Parcel,int)
location: variable arg1 of type Settings
2 errors
:myapp:compileDebugJava FAILED

By reading the error, I suppose that the compiler did not understand that the Settings class was Parcelable.

Do you have any idea of why it doesn't work ? I read numerous articles about that and it seemed pretty clear and easy to do.

ErGo_404
  • 1,801
  • 4
  • 18
  • 22
  • `Settings.aidl` should be right next to `Settings.java`, in the same package. Can you try? – Xavier Ducrohet Apr 09 '14 at 15:22
  • Settings.aidl is in the same package in the aidl/ folder. If I try to put in in a java/ folder, the aidl build fails because it could not find the import. Also, the source for the Settings class is in a pre-built jar. – ErGo_404 Apr 18 '14 at 11:51
  • Note that I tried with a dummy, much simpler program where I define my own parcelable object and a very simple aidl interface and I have the exact same issue. – ErGo_404 Apr 18 '14 at 11:53

1 Answers1

3

I know I am replying to this a little late, I ran into the same issue, others might as well. So I decide to post the resolution that worked for me.

I had to re-define my class such that it implements Parcelable, the link below contains the example I followed. Once all the required methods are defined my code compiled successfully.

http://developer.android.com/reference/android/os/Parcelable.html

Tyler

Tyler
  • 31
  • 2
  • this. the error messages are pretty clear; your custom class doesn't have a static `CREATOR` field, nor does it implement `Parcelable` these steps are required for use over AIDL. – j__m Aug 10 '14 at 01:44