user3762200
user3762200

Reputation: 447

How to import third party classes in .aidl file

I want to create a service in its own process in order to communicate to different applications.

I'm following this guide http://www.donnfelker.com/rxjava-with-aidl-services/ but I'm having issue with the .aidl file.

This is my aidl interface:

// MyAidlInteface.aidl
package my.package;

import rx.Observable;

interface MyAidlInterface {
    Observable<Integer> getPid();
}

Android Studio gives me the following error and I don't know what to do:

couldn't find import for class rx.Observable

Upvotes: 3

Views: 3238

Answers (1)

G. Blake Meike
G. Blake Meike

Reputation: 6715

There are two problems here:

  1. In order for this declaration to work, there would have to be an AIDL declaration for rx.Observable. This is the source of the AndroidStudio error. AIDL is not Java. Just because rx.Observable is visible to the Java compiler does not mean it is visible to the AIDL compiler. For your own sanity, it makes a lot of sense to put all of your AIDL into a separate top level source folder. If it is not mixed up with your Java, then errors like this are much easier to spot.
  2. The second problem is much more difficult to correct: That AIDL-visible declaration for rx.Observable would have to say something like:
package rx;

parcelable Observer;

Obviously, that won't work. rx.Observer is not Parcelable. In order to do what you are trying to do you will have to create a Parcelable object with an AIDL definition, that is a proxy to the Observer.

Upvotes: 3

Related Questions