title: Android Testing: Multiple dex files define Lorg/hamcrest/Description;
body: <p>I encounter the following runtime errors when doing the instrumentation test.</p>
  
  <pre><code>Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
  Unknown source file : com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description;
  Unknown source file :   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
  Unknown source file :   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
  Unknown source file :   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
  Unknown source file :   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
  Unknown source file :   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
  Unknown source file :   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
  Unknown source file :   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
  Unknown source file :   at com.android.dx.command.dexer.Main.run(Main.java:277)
  Unknown source file :   at com.android.dx.command.dexer.Main.main(Main.java:245)
  Unknown source file :   at com.android.dx.command.Main.main(Main.java:106)
  </code></pre>
  
  <p>I think there are many similar questions with this issue.</p>
  
  <p>However, most of them suggest to exclude the hamcrest librarty from other dependencies, but it did not solve my problem :(</p>
  
  <p>Here is the dependencies part of my <code>build.gradle</code></p>
  
  <pre><code>dependencies {
      androidTestCompile files('libs/java-hamcrest-2.0.0.0.jar')
      androidTestCompile files('libs/hamcrest-json-0.2.jar')
      androidTestCompile files('libs/jsonassert-1.2.3.jar')
      androidTestCompile ('org.powermock:powermock-module-junit4:1.6.3')
      {
          exclude module: 'hamcrest-core'
          exclude module: 'objenesis'
      }
      androidTestCompile ('org.powermock:powermock-api-mockito:1.6.3') {
          exclude module: 'hamcrest-core'
          exclude module: 'objenesis'
      }
  
      androidTestCompile ('com.android.support.test:runner:0.4.1') {
          exclude module: 'hamcrest-core'
      }
      androidTestCompile ('com.android.support.test:rules:0.4.1') {
          exclude module: 'hamcrest-core'
      }
  
  }
  </code></pre>
  
  <p>I use <code>gradle dependencies</code>  and  there is no <code>hamcrest-core</code> in <code>androidTestCompile</code>, but still fails at the instrumentation time.</p>
  
  <p>Something important I miss?</p>
  
  <p>Thank you!</p>