Can't use .aidl files across library projects?

2020-03-27 19:00发布

问题:

In the spirit of re-using code, I'm trying to create a few library projects. However, I seem to run into a problem defining .aidl files that span the libraries. Here is the problem:

In library A I have Foo.java and Foo.aidl. Foo.java is Parcelable so the aidl declaration is:

Foo.aidl:

package com.example.library.A;
parcelable Foo;

Now I'm trying to create library B. In library B I want to define a service interface that uses class Foo:

IMyService.aidl:

package com.example.library.B;
import com.example.library.A.Foo;

interface IMyService {
    void requestSomething(in Foo fooBug);
}

This file does not compile complaining that it couldn't find the import for Foo. I've tried referencing library A and I've tried adding the library project as an external jar, but neither work.

Is there a limitation that I don't know about? Am I doing something wrong with my project setup??

I should probably mention that I've used library A directly in a project with no problem so I'm confident that lib A is not the problem.

回答1:

I have it working, but I'm not happy with the solution. In lib B, I had to add a com.example.library.A package and copy the Foo.aidl file into it.



标签: android aidl