How to match the build type of an Android Gradle project dependency?

Viewed 900

I have a project with 2 modules: library and app.

The library module is of course a library and only has release and debug build types.

The app module has 4 flavors as well as the release and debug build types, giving it a total of 8 build variants. It also declares a dependency on the library module like so:

compile project(path:':library', configuration:'release')

I'd like to be able to set the library config based on the app's build variant: release build variants should use the release version of the library and debug build variants should use the debug version of the library.

The obvious answer is to list each of the 8 variants and put the proper configuration and it'll work, but that's not the optimal answer: It's ugly and clutters the build script too much.

I've attempted a few approaches with project.configurations.all{} and applicationVariants.all{} but I couldn't find a definitive way to set the dependency configuration.

Is there a cleaner way to do this?

0 Answers
Related