0

My project is in Kotlin on Android Studio 3.0.1 this is my design gradle

buildscript {
    ext.kotlin_version = '1.2.0'
    ext.anko_version='0.10.3'
    repositories {
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

In this app I'm creating a library, in this library I have the following gradient file.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.code.findbugs'
    }
    implementation('com.google.apis:google-api-services-gmail:v1-rev66-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    testImplementation 'com.greghaskins:spectrum:1.2.0'

    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.0.2'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "org.jetbrains.anko:anko-commons:$anko_version"
    implementation 'com.android.support:multidex:1.0.2'

    implementation 'com.google.android.gms:play-services-location:11.6.2'
    implementation 'com.google.android.gms:play-services-gcm:11.6.2'
    implementation 'com.google.android.gms:play-services-auth:11.6.2'

}

apply plugin: 'com.google.gms.google-services'

So far so good, the project compiles normally, but when I go build, to run the app via usb on my cell phone happens the following error that I still can not solve.

Error: Execution failed for task ': app: transformDexArchiveWithExternalLibsDexMergerForDebug'.

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

Thank you in advance for your help.

  • 1
    Is that the entire error message? In the 'Gradle Console' view, there should be more info - like, in https://stackoverflow.com/q/46053902/3934789 's case, there were multiple copies of the same class. – Cliabhach Dec 12 '17 at 18:35
  • What is written on the gradle console is this here: `FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ': app: transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org BUILD FAILED in 39s 38 actionable tasks: 19 executed, 19 up-to-date` – Danilo Furtado Dec 12 '17 at 20:05
  • Hm. Is the `--stacktrace` in that message clickable? That should force it to re-run with more information about the error. You could also open up the terminal and run `gradlew assembleDebug --stacktrace` (if you're on Windows) or `./gradlew assembleDebug --stacktrace` (if you're on anything else). If you get more info this way, add it to your question so I can read it easier. – Cliabhach Dec 12 '17 at 22:35

2 Answers2

0

When this happens to me I comment out multiDexEnabled true then do a clean/build/run.

If you application does not hit the 65k method limit you dont need to enable multidex

tyczj
  • 71,600
  • 54
  • 194
  • 296
0

A haved same problem and i sloved it by two tricks If you already enabled the multiDex, try to exclude annotation package from kotlin

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"){
  exclude group: 'org.jetbrains', module: 'annotations'
}

It's solution help me

gbixahue
  • 1,383
  • 10
  • 9