Question

I have two Android apps that share a subproject. The build.gradle in the subproject contains a dependency like this:

dependencies {
    compile "my.library.dependency:${version}"
}

What I'd like is to use this dependency at compile time, but not runtime. This is because the two apps need to link against slightly different versions of the dependency (same API).

The Gradle docs describe dependency configurations like this:

compile The dependencies required to compile the production source of the project.

runtime The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.

If runtime also includes compile dependencies, does this mean the library is exported from the subproject to the parent projects (and included in my apk)? If so, how do I prevent this? I assume it's possible because it says "by default".

Thanks in advance...

Was it helpful?

Solution

It's not clear if your subproject is using the android-library plugin, but if it is, v0.8 has added a provided scope -- see http://tools.android.com/recent/androidstudio043released.

This should work:

dependencies {
    provided "my.library.dependency:${version}"
}

If you upgrade to 0.8 of the plugin, you'll need to run Gradle 1.10 (update gradle-wrapper.properties if you're using the wrapper), and if you're using Android Studio, upgrade to 0.4.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top