title: Multiple dex files define Lcom/amazonaws/AmazonWebServiceClient;
body: <p>I am trying to use Amazon AWS SDK in my Android app. The app already uses C2Call SDK. The app is working, but as soon as I add AWS gradle libraries, it starts giving me Multiple Dex file exception. I searched for it and got to know that it is related to a single library defined multiple times, however I am not sure which one is it, from the log. I tried removing different gradle compile option and whenever I add an AWS library, it gives the Multiple Dex Exception.</p>
  
  <p>Here's my App's gradle file - </p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 22
      buildToolsVersion "21.1.2"
  
      defaultConfig {
          applicationId "com.test.test"
          minSdkVersion 14
          targetSdkVersion 22
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  repositories {
      flatDir {
          dirs 'libs'
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      /*compile 'com.android.support:appcompat-v7:22.2.0'*/
      compile(name: 'lib-c2callsdk', ext: 'aar')
      compile 'com.amazonaws:aws-android-sdk-cognito:2.2.3'
      compile 'com.amazonaws:aws-android-sdk-ses:2.2.3'
      compile 'com.amazonaws:aws-android-sdk-ddb:2.2.3'
  }
  </code></pre>
  
  <p>I tried with adding and removing appcompact too.</p>
  
  <p>Here's the error log I am getting - </p>
  
  <pre><code>Information:Gradle tasks [:app:assembleDebug]
  Warning:Dependency commons-logging:commons-logging:1.1.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
           In case of problem, please repackage it with jarjar to change the class packages
  Warning:Dependency commons-logging:commons-logging:1.1.1 is ignored for release as it may be conflicting with the internal version provided by Android.
           In case of problem, please repackage it with jarjar to change the class packages
  :app:preBuild UP-TO-DATE
  :app:preDebugBuild UP-TO-DATE
  :app:checkDebugManifest
  :app:preReleaseBuild UP-TO-DATE
  :app:prepareLibC2callsdkLibrary UP-TO-DATE
  :app:prepareDebugDependencies
  :app:compileDebugAidl UP-TO-DATE
  :app:compileDebugRenderscript UP-TO-DATE
  :app:generateDebugBuildConfig UP-TO-DATE
  :app:generateDebugAssets UP-TO-DATE
  :app:mergeDebugAssets UP-TO-DATE
  :app:generateDebugResValues UP-TO-DATE
  :app:generateDebugResources UP-TO-DATE
  :app:mergeDebugResources UP-TO-DATE
  :app:processDebugManifest UP-TO-DATE
  :app:processDebugResources UP-TO-DATE
  :app:generateDebugSources UP-TO-DATE
  :app:processDebugJavaRes UP-TO-DATE
  :app:compileDebugJava
  :app:compileDebugNdk UP-TO-DATE
  :app:compileDebugSources
  :app:preDexDebug
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$2) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$3) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$4) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$5) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.LogFactory$6) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.impl.LogFactoryImpl$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.impl.LogFactoryImpl$2) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.impl.LogFactoryImpl$3) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.impl.SimpleLog$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (com.amazonaws.services.s3.model.a.d) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  :app:dexDebug
  UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Lcom/amazonaws/AmazonWebServiceClient;
      at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
      at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
      at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
      at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
      at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
      at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
      at com.android.dx.command.dexer.Main.run(Main.java:246)
      at com.android.dx.command.dexer.Main.main(Main.java:215)
      at com.android.dx.command.Main.main(Main.java:106)
  Error:Execution failed for task ':app:dexDebug'.
  &gt; com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
  Information:BUILD FAILED
  Information:Total time: 25.398 secs
  Information:1 error
  Information:2 warnings
  Information:See complete output in console
  </code></pre>
  
  <p>If I select just one of the AWS libraries such as cognito, it gives the same exception without those long warnings.</p>
  
  <p>Any idea what I am doing wrong here and how can I find the exact issue?</p>
  
  <p><strong>Update:</strong>  </p>
  
  <p>I have tried putting the following in the app's gradle - </p>
  
  <pre><code>dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      /*compile 'com.android.support:appcompat-v7:22.2.0'*/
      compile(name: 'lib-c2callsdk', ext: 'aar'){
          exclude group:'gson'
          exclude group:'commons-logging'
      }
      compile ('com.amazonaws:aws-android-sdk-core:2.+'){
          exclude group:'gson'
          exclude group:'commons-logging'
      }
      /*compile 'com.amazonaws:aws-android-sdk-cognito:2.+'
      compile 'com.amazonaws:aws-android-sdk-ses:2.+'
      compile 'com.amazonaws:aws-android-sdk-ddb:2.+'*/
      /*compile 'com.google.code.gson:gson:2.3'*/
  }
  </code></pre>
  
  <p>And now the error is reduced to this - </p>
  
  <pre><code>Information:Gradle tasks [:app:assembleDebug]
  :app:preBuild UP-TO-DATE
  :app:preDebugBuild UP-TO-DATE
  :app:checkDebugManifest
  :app:preReleaseBuild UP-TO-DATE
  :app:prepareLibC2callsdkLibrary UP-TO-DATE
  :app:prepareDebugDependencies
  :app:compileDebugAidl UP-TO-DATE
  :app:compileDebugRenderscript UP-TO-DATE
  :app:generateDebugBuildConfig UP-TO-DATE
  :app:generateDebugAssets UP-TO-DATE
  :app:mergeDebugAssets UP-TO-DATE
  :app:generateDebugResValues UP-TO-DATE
  :app:generateDebugResources UP-TO-DATE
  :app:mergeDebugResources UP-TO-DATE
  :app:processDebugManifest UP-TO-DATE
  :app:processDebugResources UP-TO-DATE
  :app:generateDebugSources UP-TO-DATE
  :app:processDebugJavaRes UP-TO-DATE
  :app:compileDebugJava UP-TO-DATE
  :app:compileDebugNdk UP-TO-DATE
  :app:compileDebugSources UP-TO-DATE
  :app:preDexDebug UP-TO-DATE
  :app:dexDebug
  UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Lcom/amazonaws/AmazonWebServiceClient;
      at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
      at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
      at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
      at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
      at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
      at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
      at com.android.dx.command.dexer.Main.run(Main.java:246)
      at com.android.dx.command.dexer.Main.main(Main.java:215)
      at com.android.dx.command.Main.main(Main.java:106)
  Error:Execution failed for task ':app:dexDebug'.
  &gt; com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
  Information:BUILD FAILED
  Information:Total time: 2.804 secs
  Information:1 error
  Information:0 warnings
  Information:See complete output in console
  </code></pre>