Error:Execution failed for task ':app:dexDebug' error in my project while I added new dependency

Solution 1:

you can use below code also with IntelliJ Amiya answer. In some case this code work for me

 dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

android {
compileSdkVersion 23
 buildToolsVersion "23.0.1"

     defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }
}

you can do by make an Application class

public class MyApplication extends MultiDexApplication { .. }

or

override 
 attachBaseContext method and call MultiDex.install().
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

Otherwise (if your application does not have custom Application implementation), declare MultiDexApplication as application implementation in your AndroidManifest.xml.

<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>

Solution 2:

At first you can use compile 'com.squareup.okhttp:okhttp:2.5.0' instead of yours . You can read my answer DexIndexOverflowException

android {
    compileSdkVersion 23
buildToolsVersion "23.0.1"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
}

http://developer.android.com/intl/es/tools/building/multidex.html