Gradle build failed: Dex files cannot exceed 64k
<p>Whenever I build by project and prepare for launch on my device, I keep getting this error:</p>

<blockquote>
  <p>Error:The number of method references in a .dex file cannot exceed 64K.
  Learn how to resolve this issue at <a href="https://developer.android.com/tools/building/multidex.html" rel="nofollow noreferrer">https://developer.android.com/tools/building/multidex.html</a></p>
</blockquote>

<p>Additionally, I get this error:</p>

<blockquote>
  <p>Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
  com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 2</p>
</blockquote>

<p>And it says gradle build failed with two errors</p>

<p>So I have some questions:</p>

<ul>
<li>What are dex files</li>
<li>I'm not using them directly, so why do I get the errors above?</li>
<li>What are in dex files?</li>
<li>Do these files have anything to say for the .APK file size?</li>
</ul>

<p>These errors started appearing again after I stopped using proguard for debug builds as the StackTrace did not show and right before I activated proguard I had the error.</p>

<p>I had this error once before and I deleted the dex folder and it solved it but now it suddenly isn't enough anymore.</p>

<p>my gradle file:</p>

<pre><code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.myproject"
        minSdkVersion 15
        targetSdkVersion 23

    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }
}

dependencies {

    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.google.android.gms:play-services:9.2.0'
    compile 'com.google.android.gms:play-services-ads:9.2.0'
}
</code></pre>