Why does Gradle build my module in Release mode when the app is in Debug

Put this in your app dependencies:

dependencies {
    debugCompile project(path: ':custom_lib', configuration: "debug")
    releaseCompile project(path: ':custom_lib', configuration: "release")
}

and in your library’s build.gradle add:

android {

    defaultConfig {
        defaultPublishConfig 'release'
        publishNonDefault true
    }

}

Then the library will be built in the same mode as the app. Contrary to previous revisions of this answer, I’ve confirmed a flavor is not required on the library (this may be due to Gradle or Android plugin versions – I’m using Gradle 2.14 and Android plugin 2.1.0 and did not require it).

Edit: You may have trouble if you don’t clean/rebuild after modifying the gradle files, as outlined in this answer here.

Leave a Comment