Android无法合并dex错误。查看内容

时间:2018-01-12 02:28:22

标签: android gradle android-build

  

错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。   java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

我使用的是Android Studio 3.0.1版。

我也试过'清理项目'和'重建项目'。

* 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'
}

当我进行重建项目时,我收到如下错误。

  

错误:任务':app:transformClassesWithMultidexlistForDebug'的执行失败。   java.io.IOException:无法写[C:\ Users \ backkom \ AndroidStudioProjects \ SpeechTest \ app \ build \ intermediates \ multi-dex \ debug \ componentClasses.jar](无法读取[C:\ Users \ backkom] .gradle \缓存\模块-2 \文件-2.1 \ com.google.protobuf \的protobuf-java的\ 3.3.1 \ e8964a2667e55d11a4505b329a4c34247663920b \的protobuf-java的3.3.1.jar(;;;;;; **。类) ](重复的zip条目[protobuf-java-3.3.1.jar:com / google / protobuf / ExperimentalApi.class]))

1 个答案:

答案 0 :(得分:0)

检查您是否(直接或传递)使用com.google.protobuf:protobuf-javacom.google.protobuf:protobuf-lite组合APK。后者包括前者的一个类的子集,当dexer找到重复的第一个类时,它会抱怨。你应该排除其中一个。

  1. 如果您想严格仅使用Protobuf OR的精简子集,请排除protobuf-java
  2. 删除implementation ... protobuf-lite行并让ProGuard删除您不需要的课程