Search code examples
androidbuild-errorandroid-studio-3.1

Android Studio 3.1 Execution failed for task: Error while merging dex archives


android studio was getting build error while build execution with following

Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. com.android.build.api.transform.TransformException: Error while generating the main dex list.

here is my gradle file where i am adding some jar dependency.

App.gradle

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.demo"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    implementation files('libs/commons-codec-1.4.jar')
    implementation files('libs/commons-codec-1.9.jar')
    implementation files('libs/opencsv-2.4.jar')
    implementation files('libs/ormlite-android-4.46.jar')
    implementation files('libs/ormlite-core-4.46.jar')
    implementation files('libs/Pushwoosh.jar')
    implementation files('libs/StartAppInApp-2.3.2.jar')
}

Project.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

Solution

  • Use need to ensure multidex is true in build.gradle.

        android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"
    
         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22
    
             // Enabling multidex support.
             multiDexEnabled true
         }
          }
    
     dependencies {
      compile 'com.android.support:multidex:1.0.3'
       }
    

    you can also create a class that extends multidex and that class should be mention in application tag.