I have a project consisting of multiple gradle modules (plugin com.android.library) referencing each other (tree, not flat). I use AIDL intensively and thus it happens that I reference AIDL interfaces from one module (modA) in an AIDL interface in another module (modB).
modA/src/main/aidl/modA/foo.aidl:
package modA;
interface foo {
void modAcall();
}
modB/src/main/aidl/modB/bar.aidl:
package modB;
import modA.foo;
interface bar {
foo modBcall();
}
modB/build.gradle:
dependencies {
compile project(':modA')
}
I can reference parcelables of modA in AIDL files in modB and I can reference interfaces of modA in java code in modB, but not in AIDL in modB. Instead the error message couldn't find import for class
is shown by the aidl tool.
I noticed that .aar-files also do not contain information on the aidl interfaces of the library, only the parcelables are listed. I guess this has the same reason as the problem described above.
As I already have the aidl files in one place I don't want to copy them over to another subproject, because changes have to be manually copied over in that case. I also don't like the idea of using symlinks for this, because it feels wrong to modify the src directory of modB to include something from modA.
I found a solution. There is an apparently undocumented feature in Android gradle build tools to include arbitrary aidl files into the output .aar file. This makes it possible to reference them in other subprojects.
// In modA build.gradle
android {
aidlPackageWhiteList "src/main/aidl/foo.aidl"
}
This is far from ideal, but at least usable to solve my problem.
EDIT: Clarify that this would be in modA (the library), not modB (which is a library according to the question, but not in all possible cases).