2
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}




apply plugin: 'com.android.application'

android {
    signingConfigs {
    }
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId 'net.example.net.app'
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/DEPENDENCIES'
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile('org.apache.httpcomponents:httpmime:4.3.4') {
        exclude module: 'org.apache.httpcompoents:httpcore'
        exclude module: 'org.apache.httpcompoents:httpclient'
    }
    compile 'org.codehaus.jackson:jackson-core-asl:1.8.3'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.8.3'
}

Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.dex.DexException: Multiple dex files define Lorg/apache/http/conn/socket/LayeredConnectionSocketFactory;

jradich1234
  • 1,410
  • 5
  • 24
  • 29
minsu007
  • 21
  • 1

4 Answers4

2

Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

You should upgrade your gms:play-services & com.android.support version.

 compile 'com.google.android.gms:play-services:11.6.0' //11.8.0
 compile 'com.android.support:support-v4:26.0.2'
 compile 'com.android.support:appcompat-v7:26.0.2'

After that, Clean-Rebuild-Run.

FYI

Enable multiDexEnabled .

 defaultConfig {
        multiDexEnabled true
    }
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You have enabled Multidex but missed to add dependency, add the following in dependencies

compile 'com.android.support:multidex:1.0.2'

then make sure your application class extends MultidexApplication. Finally clean and rebuild project. Hope this will fix the issue

For more check multidex doc in developer.android

AbuMaaiz
  • 492
  • 4
  • 19
0

It is because httpmime include httpclient in its dependencies. You need to exclude it. Currently, you're using the wrong package name for excluding the httpclient:

compile('org.apache.httpcomponents:httpmime:4.3.4') {
    exclude module: 'org.apache.httpcompoents:httpcore'
    exclude module: 'org.apache.httpcompoents:httpclient'
}

it should be:

compile('org.apache.httpcomponents:httpmime:4.3.4') {
   exclude group: 'org.apache.httpcomponents', module: 'httpcore'
   exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
0

if you got this error with phonegap/cordova so don't waste your time go back and regenerate new project on different path. its work in my condition

Roshan
  • 1
  • 2