0

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

I am using version 3.0.1 of Android Studio.

I also tried 'clean project' and 'rebuild project'.

*project build gradle

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'

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

*module build gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
ext {
    grpcVersion = '1.4.0'
}

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.example.backkom.speechtest"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled  true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
    }
}

protobuf {
    protoc {
       artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    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'

    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    // gRPC
    compile "io.grpc:grpc-okhttp:$grpcVersion"
    compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
    compile "io.grpc:grpc-stub:$grpcVersion"
    compile 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.3.1'

    compile group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '0.1.13'

    // OAuth2 for Google API
    compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
    exclude module: 'httpclient'
    }

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

When I do a rebuild project, I get an error like below.

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [C:\Users\backkom\AndroidStudioProjects\SpeechTest\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\backkom.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java\3.3.1\e8964a2667e55d11a4505b329a4c34247663920b\protobuf-java-3.3.1.jar(;;;;;;**.class)] (Duplicate zip entry [protobuf-java-3.3.1.jar:com/google/protobuf/ExperimentalApi.class]))

Backkom
  • 105
  • 2
  • 10

2 Answers2

-1

From your error log it seems like your directory backkom is not available for android studio . so please check your directory

 C:\Users\backkom

is writable or not . by doing so . go to that directory and check its permission . is it has read and write both permission or not .

Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
  • There seems to be no problem with permissions. I checked the permissions on the directory, but I had read / write permissions. – Backkom Jan 12 '18 at 06:00
  • @Backkom . from your log `Duplicate zip entry [protobuf-java-3.3.1.jar:com/google/protobuf/ExperimentalApi.class]` . i think you have some problem with protobuf . you can visit [this](https://github.com/google/protobuf-gradle-plugin/issues) . it might solve your problem. – Tejas Pandya Jan 12 '18 at 06:21
  • 1
    I found a problem. google-protobuf does not support 3.0.1. So there was a build error. We changed the gradle version to 2.3.3. I changed other code parts too. Thanks to everyone who answered. – Backkom Jan 12 '18 at 06:59
  • @Backkom i knew that you were having problem with protobuf not multidex . that's why i have pointed you that way – Tejas Pandya Jan 12 '18 at 07:36
-1

As per my understanding,

Try this :

Clean Project button.
Rebuild Project button from the Build menu.

And change your local.properties with this

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

And define gradle in this way

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 21
targetSdkVersion 26
versionCode 7
versionName "0.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

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

}

And add this multidex in your project

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

and Define it in Manifest

coder_baba
  • 447
  • 3
  • 21