生成签名的APK时出现DexArchiveMergerException

时间:2018-10-30 20:38:07

标签: android apk signed

当尝试构建 SIGNED android apk时,我遇到了DexArchiveMergerException。它仅在带签名的apk时发生。如果我调试应用程序或构建未签名的APK,则一切正常。

我已经尝试清理项目,使缓存无效并重新启动,删除构建文件夹,但是没有任何帮助。不言而喻的是过度依赖。它指的是MultiDex。但是我不知道有什么特别的。

您能帮我吗?

这是我的build.gradle文件:

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

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.incubasys.tahlilaty"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            buildConfigField "String", "SERVER_PREFIX", ""
            buildConfigField "String", "SOCKET_SERVER", ""
            buildConfigField "String", "SOCKET_PROTOCOL", ""
            debuggable true
        }
        release {
            buildConfigField "String", "SERVER_PREFIX", ""
            buildConfigField "String", "SOCKET_SERVER", ""
            buildConfigField "String", "SOCKET_PROTOCOL", ""
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

ext {
    supportLibraryVersion = "28.0.0"
    supportMutliDexLibraryVersion = "1.0.3"
    supportDesignVersion = "1.0.0"
    constraintLayoutVersion = "1.1.3"
    flexBoxVersion = "1.0.0"
    googleGmsServiceVersion = "16.0.1"
    ciceroneVersion = "4.0.2"
    rxJavaVersion = "2.1.6"
    rxAndroidVersion = "2.0.1"
    daggerVersion = "2.14.1"
    retrofit2Version = "2.4.0"
    okhttp3Version = "3.11.0"
    gsonVersion = "2.8.5"
    lombokVersion = "1.18.0"
    androidAnnotationsVersion = "4.5.2"
    accountKitVersion = "4.34.0"
    firebaseCoreVersion = "16.0.4"
    firebaseMessagingVersion = "17.3.4"
    moxyVersion = "1.5.5"
    lottieVersion = "2.7.0"
    timberVersion = "4.7.1"
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "com.android.support:multidex:$supportMutliDexLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support.constraint:constraint-layout:$constraintLayoutVersion"
    implementation "com.google.android:flexbox:$flexBoxVersion"

    implementation "com.google.android.gms:play-services-auth:$googleGmsServiceVersion"

    //Cicerone
    implementation "ru.terrakok.cicerone:cicerone:$ciceroneVersion"

    // RxJava and RxAndroid
    implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"

    //Dagger2
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"
    implementation "com.google.dagger:dagger:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    //Retrofit 2
    implementation "com.squareup.retrofit2:retrofit:$retrofit2Version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit2Version"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2Version"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version"

    //Gson
    implementation "com.google.code.gson:gson:$gsonVersion"

    //Joda
    implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'

    // Lombok
    compileOnly "org.projectlombok:lombok:$lombokVersion"
    annotationProcessor "org.projectlombok:lombok:$lombokVersion"

    //AndroidAnnotations
    annotationProcessor "org.androidannotations:androidannotations:$androidAnnotationsVersion"
    implementation "org.androidannotations:androidannotations-api:$androidAnnotationsVersion"
    kapt "org.androidannotations:androidannotations:$androidAnnotationsVersion"

    //Account Kit
    implementation "com.facebook.android:account-kit-sdk:$accountKitVersion"

    //Firebase
    implementation "com.google.firebase:firebase-core:$firebaseCoreVersion"
    implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"

    //Moxy
    implementation "com.arello-mobile:moxy:$moxyVersion"
    implementation "com.arello-mobile:moxy-android:$moxyVersion"
    implementation "com.arello-mobile:moxy-app-compat:$moxyVersion"
    annotationProcessor "com.arello-mobile:moxy-compiler:$moxyVersion"

    implementation "com.airbnb.android:lottie:$lottieVersion"

    // Timber
    implementation "com.jakewharton.timber:timber:$timberVersion"

    // EventBus
    implementation 'org.greenrobot:eventbus:3.1.1'

    testImplementation 'junit:junit:4.12'
}

还有一个项目build.gradle:

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

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        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
}

错误是:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\0, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\1, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\externalLibsDexMerger\release\0
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
    at sun.reflect.GeneratedMethodAccessor2143.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
    ... 33 more
Caused by: com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\0, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\1, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\externalLibsDexMerger\release\0
    at com.android.build.gradle.internal.transforms.DexMergerTransform.transform(DexMergerTransform.java:225)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 48 more
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\0, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\1, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\externalLibsDexMerger\release\0
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1431)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:326)
    at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:391)
    at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
    at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:397)
    at com.android.build.gradle.internal.transforms.DexMergerTransform.transform(DexMergerTransform.java:221)
    ... 51 more
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\0, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\dexBuilder\release\1, C:\Android_projects\Tahlilaty\app\build\intermediates\transforms\externalLibsDexMerger\release\0
    at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:124)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:109)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:36)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
    ... 57 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
    at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:76)
    at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:45)
    at com.android.tools.r8.D8.run(D8.java:67)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:107)
    ... 60 more
Caused by: com.android.tools.r8.utils.AbortException
    at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:77)
    at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:58)
    at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:67)
    ... 63 more

1 个答案:

答案 0 :(得分:0)

该决定在Lombok库中进行:将版本降低到1.16.20解决了该问题。