0

im getting the Unable to merge dex error when I'm trying to build my project. I literally tried every solution on the other threads, but I couldn't find one that would work for me... So please dont mark this as a duplicate right away.

So here is the exact error:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

My build.gradle(project) file:

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    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
}

and my module build.gradle:

apply plugin: 'com.android.application'

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

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.google.code.gson:gson:2.8.2'
    compile 'com.android.support:appcompat-v7:27.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

As external libraries i use GSON.

leodriesch
  • 5,308
  • 5
  • 30
  • 52
  • Please add rest part of error log if it has more lines. Some classes are duplicate and they should appear in the log. Also need to know you are using external libraries. – Toris Nov 29 '17 at 19:58
  • there is not more, just the error i copied into the question. I looked only in the "Messages Gradle Build" section, or is there any other place where i can see the errors? – leodriesch Nov 29 '17 at 20:19
  • 1
    why did you commented your buildTools? add buildToolsVersion '27.0.1' and clean your project – Viktor Yakunin Nov 29 '17 at 20:25
  • maybe related: https://stackoverflow.com/questions/47360856/unable-to-merge-dex-android-studio-3-0-build-error/47383686#47383686 To get stacktrace: https://stackoverflow.com/questions/21674091/how-to-add-stacktrace-or-debug-option-when-building-android-studio-project – Toris Nov 29 '17 at 20:33
  • error is still there... – leodriesch Nov 29 '17 at 20:34
  • Please post dependencies tree. To get dependency tree: https://stackoverflow.com/questions/39008887/how-do-i-show-dependencies-tree-in-android-studio/39020703 – Toris Nov 29 '17 at 20:39

1 Answers1

0

Tried to enable multidex

modify your build.gradle

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

defaultConfig {
    multiDexEnabled true

}

in your manifiest file define your apllication name properrty like this

android:name="com.pkg.YouApplication"

Include this in your Application class

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56