title: Android Studio Gradle error "Multiple dex files define..."
body: <p>My Project was working fine, when I have added facebook sdk into my project I have an error like this, I have tried so many ways to fix this, but I didn't. What should I do?</p>
  
  <pre><code>  Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
  &gt; java.util.zip.ZipException: duplicate entry: bolts/AggregateException.class
  </code></pre>
  
  <p>My App gradle is below</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion '21.1.2'
  
      defaultConfig {
          applicationId "com.example.myproject"
          minSdkVersion 9
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
          multiDexEnabled = true
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_7
          targetCompatibility JavaVersion.VERSION_1_7
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
  
      compile project(':facebook')
  }
  </code></pre>
  
  <p>And here is the facebook build.gradle</p>
  
  <pre><code>apply plugin: 'com.android.library'
  
  repositories {
    mavenCentral()
  }
  
  project.group = 'com.facebook.android'
  
  dependencies {
      compile 'com.android.support:support-v4:[21,22)'
      compile 'com.parse.bolts:bolts-android:1.1.4'
  }
  
  android {
      compileSdkVersion 21
      buildToolsVersion '21.1.2'
  
      defaultConfig {
          minSdkVersion 9
          targetSdkVersion 21
      }
  
      lintOptions {
          abortOnError false
      }
  
      sourceSets {
          main {
              manifest.srcFile 'AndroidManifest.xml'
              java.srcDirs = ['src']
              res.srcDirs = ['res']
          }
      }
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_7
          targetCompatibility JavaVersion.VERSION_1_7
      }
  }
  
  apply plugin: 'maven'
  apply plugin: 'signing'
  
  def isSnapshot = version.endsWith('-SNAPSHOT')
  def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
  def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
  
  task setVersion {
      // The version will be derived from source
      project.version = null
      def sdkVersionFile = file('src/com/facebook/FacebookSdkVersion.java')
      sdkVersionFile.eachLine{
          def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
          if (matcher.matches()) {
            project.version = matcher[0][1]
            return
          }
      }
      if (project.version.is('unspecified')) {
        throw new GradleScriptException('Version could not be found.', null)
      }
  }
  
  uploadArchives {
      repositories.mavenDeployer {
          beforeDeployment { MavenDeployment deployment -&gt; signing.signPom(deployment) }
  
          repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
              authentication(userName: ossrhUsername, password: ossrhPassword)
          }
  
          snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
              authentication(userName: ossrhUsername, password: ossrhPassword)
          }
  
          pom.project {
              name 'Facebook-Android-SDK'
              artifactId = 'facebook-android-sdk'
              packaging 'aar'
              description 'Facebook Android SDK'
              url 'https://github.com/facebook/facebook-android-sdk'
  
              scm {
                  connection 'scm:git@github.com:facebook/facebook-android-sdk.git'
                  developerConnection 'scm:git@github.com:facebook/facebook-android-sdk.git'
                  url 'https://github.com/facebook/facebook-android-sdk'
              }
  
              licenses {
                  license {
                      name 'The Apache Software License, Version 2.0'
                      url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
                      distribution 'repo'
                  }
              }
  
              developers {
                  developer {
                      id 'facebook'
                      name 'Facebook'
                  }
              }
          }
      }
  }
  
  uploadArchives.dependsOn(setVersion)
  
  signing {
      required { !isSnapshot &amp;&amp; gradle.taskGraph.hasTask("uploadArchives") }
      sign configurations.archives
  }
  
  task androidJavadocs(type: Javadoc) {
      source = android.sourceSets.main.java.srcDirs
      classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
  }
  
  task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
      classifier = 'javadoc'
      from androidJavadocs.destinationDir
  }
  
  task androidSourcesJar(type: Jar) {
      classifier = 'sources'
      from android.sourceSets.main.java.sourceFiles
  }
  
  artifacts {
      archives androidSourcesJar
      archives androidJavadocsJar
  }
  
  afterEvaluate {
      androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
  }
  </code></pre>