Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use AIDL interfaces across module/subprojects in Gradle

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.

  • Is there a way to include aidl interfaces in aar so it can be used by other modules?
  • Is it possible to extend the aidl include path in Gradle to use the aidl files of the dependency module (for subprojects, it should be possible, because the aidl files are present on filesystem) without "compiling" them again (the class files of the generated java interface/classes are already included in the aar/module import)?
like image 674
Marvin W Avatar asked Aug 04 '16 10:08

Marvin W


2 Answers

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).

like image 108
Marvin W Avatar answered Nov 15 '22 12:11

Marvin W


I try 'aidlPackageWhiteList' , it shows me "aidlPackageWhiteList is not supported" , so I try another way below, it works for me.

  // in modB build.gradle
  android {
        sourceSets {
            main {
                aidl.srcDirs += '../src/main/aidl'    // locate your modA aidl directory 
            }
        }
    }
like image 1
owl Avatar answered Nov 15 '22 14:11

owl