title: Can't generate APK in android studio
body: <p>I have an android application ready to release. I'm trying to generate the APK in the android studio in the section 'build apk'. I'm using some externals libraries. However, I'm getting errors related to bytecode to dex. I already search for solutions, but no success.  </p>
  
  <p>This is the errors:
  </p>
  
  <pre><code>Information:Gradle tasks [:app:assembleDebug]
  Error:Error converting bytecode to dex:
  Cause: com.android.dex.DexException: Multiple dex files define Lcom/loopj/android/http/AsyncHttpResponseHandler;
  Error:com.android.dex.DexException: Multiple dex files define Lcom/loopj/android/http/AsyncHttpResponseHandler;
  Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
  Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
  Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
  Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
  Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
  Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
  Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
  Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
  Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
  Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
  Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
  Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
  Error:Error converting bytecode to dex:
  Cause: com.android.dex.DexException: Multiple dex files define Lcom/loopj/android/http/BaseJsonHttpResponseHandler;
  Error:com.android.dex.DexException: Multiple dex files define Lcom/loopj/android/http/BaseJsonHttpResponseHandler;
  Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
  Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
  Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
  Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
  Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
  Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
  Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
  Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
  Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
  Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
  Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
  Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
  Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
  &gt; com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/loopj/android/http/BaseJsonHttpResponseHandler;
  </code></pre>
  
  
  
  <p>And this is <code>build.gradle</code> :</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 25
      buildToolsVersion '26.0.2'
      defaultConfig {
          applicationId "com.NanoStima.AndroidClient"
          minSdkVersion 19
          targetSdkVersion 22
          multiDexEnabled true
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
      exclude group: 'com.android.support', module: 'support-annotations'
  })
      compile 'com.android.support:appcompat-v7:25.1.1'
      testCompile 'junit:junit:4.12'
      compile files('libs/activation.jar')
      compile files('libs/additionnal.jar')
      compile files('libs/mail.jar')
  }
  
  dependencies {
      compile 'com.google.android.gms:play-services:9.2.0'
      compile 'com.google.android.gms:play-services-location:9.2.0'
      compile 'com.facebook.android:facebook-android-sdk:4.26.0'
      compile 'com.android.support:multidex:1.0.1'
  }
  
   dependencies {
      //   compile 'com.github.scribejava:scribejava-apis:3.2.0'
      compile 'com.loopj.android:android-async-http:1.4.4'
      compile group: 'org.mindrot', name: 'jbcrypt', version: '0.3m'
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:25.0.1'
      compile 'com.android.support:design:25.0.1'
  }
  </code></pre>
  
  <p>Can anyone help?</p>
  
  <p>WARNING NEW: I was testing some of your sugestions and the project just dont run anymore. I made a reroll for the initial gradle, and still have this error :
  Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex</p>
  </blockquote>
  
  <p>I already clean the project, delete .gradle, restart android studio. Just dont run anymore :\</p>