title: Why does Gradle build my module in Release mode when the app is in Debug
body: <p>I'm making a new Android project, with the standard <code>'app'</code> module, as well as a library project (let's call it <code>'custom_lib'</code>). In the <code>app</code>'s <code>build.gradle</code> file, I link the module as such : </p>
  
  <pre><code>dependencies {
      compile project(':custom_lib')
  }
  </code></pre>
  
  <p>When I trigger the build process (Menu <code>Build</code> > <code>Make Project</code>), I get the following output in the Gradle console</p>
  
  <pre><code>Executing tasks: [clean, :app:compileDebugSources, :custom_lib:compileDebugSources]
  
  Configuration on demand is an incubating feature.
  :app:clean
  :custom_lib:clean
  :app:preBuild
  :app:preDebugBuild
  :app:checkDebugManifest
  :app:preReleaseBuild
  :custom_lib:compileLint
  :custom_lib:copyReleaseLint UP-TO-DATE
  :custom_lib:mergeReleaseProguardFiles UP-TO-DATE
  :custom_lib:preBuild
  :custom_lib:preReleaseBuild
  :custom_lib:checkReleaseManifest
  :custom_lib:prepareReleaseDependencies
  :custom_lib:compileReleaseAidl
  :custom_lib:compileReleaseRenderscript
  :custom_lib:generateReleaseBuildConfig
  :custom_lib:generateReleaseAssets UP-TO-DATE
  :custom_lib:mergeReleaseAssets
  :custom_lib:generateReleaseResValues UP-TO-DATE
  :custom_lib:generateReleaseResources
  :custom_lib:packageReleaseResources
  :custom_lib:processReleaseManifest
  :custom_lib:processReleaseResources
  :custom_lib:generateReleaseSources
  :custom_lib:compileReleaseJava
  :custom_lib:processReleaseJavaRes UP-TO-DATE
  :custom_lib:packageReleaseJar
  :custom_lib:compileReleaseNdk
  :custom_lib:packageReleaseJniLibs UP-TO-DATE
  :custom_lib:packageReleaseLocalJar UP-TO-DATE
  :custom_lib:packageReleaseRenderscript UP-TO-DATE
  :custom_lib:bundleRelease
  :app:prepareComAndroidSupportAppcompatV72102Library
  :app:prepareComAndroidSupportSupportV42102Library
  :app:prepareTestDoubleBuildCustom_libUnspecifiedLibrary
  :app:prepareDebugDependencies
  :app:compileDebugAidl
  :app:compileDebugRenderscript
  :app:generateDebugBuildConfig
  :app:generateDebugAssets UP-TO-DATE
  :app:mergeDebugAssets
  :app:generateDebugResValues UP-TO-DATE
  :app:generateDebugResources
  :app:mergeDebugResources
  :app:processDebugManifest
  :app:processDebugResources
  :app:generateDebugSources
  :app:compileDebugJava
  :app:compileDebugNdk
  :app:compileDebugSources
  :custom_lib:preDebugBuild
  :custom_lib:checkDebugManifest
  :custom_lib:prepareDebugDependencies
  :custom_lib:compileDebugAidl
  :custom_lib:compileDebugRenderscript
  :custom_lib:generateDebugBuildConfig
  :custom_lib:generateDebugAssets UP-TO-DATE
  :custom_lib:mergeDebugAssets
  :custom_lib:generateDebugResValues UP-TO-DATE
  :custom_lib:generateDebugResources
  :custom_lib:packageDebugResources
  :custom_lib:processDebugManifest
  :custom_lib:processDebugResources
  :custom_lib:generateDebugSources
  :custom_lib:compileDebugJava
  :custom_lib:compileDebugNdk
  :custom_lib:compileDebugSources
  
  BUILD SUCCESSFUL
  
  Total time: 2.184 secs
  </code></pre>
  
  <p>What puzzles me is that the build mechanism triggers a Debug build (as the first line says), but almost immediately, Gradle uses the task <code>:app:preReleaseBuild</code> which make my <code>custom_lib</code> module to be built with the Release configuration. </p>
  
  <p>And then, after the app is fully built, Gradle compiles my module with the Debug configuration. </p>
  
  <p>So my questions are : </p>
  
  <ul>
  <li>Why is it doing this double build which seems incoherent ? </li>
  <li>How can I make sure that the library is built with debug configuration when I launch a Debug build process ? </li>
  </ul>
  
  <p>EDIT : </p>
  
  <p>app/build.gradle : </p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.1"
  
      defaultConfig {
          applicationId "com.deezer.testdoublebuild"
          minSdkVersion 8
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
  
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_7
          targetCompatibility JavaVersion.VERSION_1_7
      }
      buildTypes {
          debug{
              debuggable true
          }
          release {
              debuggable false
              minifyEnabled false
          }
      }
  }
  
  dependencies {
      compile project(':custom_lib')
  }
  </code></pre>
  
  <p>custom_lib/build.gradle : </p>
  
  <pre><code>apply plugin: 'com.android.library'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.1"
  
      defaultConfig {
          applicationId "com.deezer.mylibrary"
          minSdkVersion 8
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
  
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_7
          targetCompatibility JavaVersion.VERSION_1_7
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
  }
  </code></pre>
  
  <p><strong><em>Note</strong> : I'm using Android Studio 1.0 RC 1 / Gradle 2.2, and reproduced this issue by creating a new project from scratch, add an empty Android Library module, and "voila"</em></p>