Different dependencies for debug and release in gradle and Android Studio

Meteorite picture Meteorite · Mar 16, 2014 · Viewed 36.3k times · Source

I have an Android project, that depends on pure Java project. Both of them depend on another Java library, also in my multiproject gradle set in Android Studio. I have two versions of that library and want both Android and Java projects to depend on one of them in debug mode, and another - in release.

Is it possible for Android project? For pure Java project? How?

Answer

athor picture athor · Mar 16, 2014

Build Types (debug, release, or custom) can have their own dependencies.

To specify a dependency specific to a build type, do the following:

dependencies {
    debugCompile "mydebugdependency"
    releaseCompile "myreleasedependency"
}

If your java project and android project are both using gradle, you can do the above in both of their build.gradle files.