我正在运行Android Studio 3.0。我目前正在尝试使Glide 4.3.0版正常工作,但是在4.2.0版中存在相同的问题。

我的项目运行正常,而没有在我的build.gradle文件中添加Glide软件包依赖项,该文件从此处https://github.com/bumptech/glide下载。我也按照这里的设置说明进行操作。首先,将jar文件添加到我的libs文件夹中,然后添加依赖项。

完整的错误是

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

我已经对这个问题进行了很多研究,但是只找到了针对其他软件包的解决方案,这些解决方案为这些软件包提供了特定的修复程序,但是我找不到针对该特定软件包的解决方案。

这是完整的gradle堆栈跟踪。
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    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:248)
    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:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.RuntimeException: java.io.IOException: Can't write [C:\Users\Alex\AndroidStudioProjects\ChanReader\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\Alex\.gradle\caches\modules-2\files-2.1\com.github.bumptech.glide\glide\4.3.0\5ef2a3700ab3320576eab21ff504189e5a92a350\glide-4.3.0.jar(;;;;;;**.class)] (Duplicate zip entry [glide-4.3.0.jar:com/bumptech/glide/util/Synthetic.class]))
    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:213)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    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:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 27 more
Caused by: java.io.IOException: Can't write [C:\Users\Alex\AndroidStudioProjects\ChanReader\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\Alex\.gradle\caches\modules-2\files-2.1\com.github.bumptech.glide\glide\4.3.0\5ef2a3700ab3320576eab21ff504189e5a92a350\glide-4.3.0.jar(;;;;;;**.class)] (Duplicate zip entry [glide-4.3.0.jar:com/bumptech/glide/util/Synthetic.class]))
    at proguard.OutputWriter.writeOutput(OutputWriter.java:187)
    at proguard.OutputWriter.execute(OutputWriter.java:79)
    at proguard.ProGuard.writeOutput(ProGuard.java:427)
    at proguard.ProGuard.execute(ProGuard.java:175)
    at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:61)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.shrinkWithProguard(MainDexListTransform.java:232)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.transform(MainDexListTransform.java:184)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 39 more
Caused by: java.io.IOException: Can't read [C:\Users\Alex\.gradle\caches\modules-2\files-2.1\com.github.bumptech.glide\glide\4.3.0\5ef2a3700ab3320576eab21ff504189e5a92a350\glide-4.3.0.jar(;;;;;;**.class)] (Duplicate zip entry [glide-4.3.0.jar:com/bumptech/glide/util/Synthetic.class])
    at proguard.InputReader.readInput(InputReader.java:188)
    at proguard.InputReader.readInput(InputReader.java:158)
    at proguard.OutputWriter.writeOutput(OutputWriter.java:176)
    ... 48 more
Caused by: java.io.IOException: Duplicate zip entry [glide-4.3.0.jar:com/bumptech/glide/util/Synthetic.class]
    at proguard.io.JarWriter.getOutputStream(JarWriter.java:138)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:92)
    at proguard.io.ClassRewriter.read(ClassRewriter.java:68)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.JarReader.read(JarReader.java:65)
    at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:65)
    at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)
    at proguard.InputReader.readInput(InputReader.java:184)
    ... 50 more

最佳答案

问题是将jar文件添加到我项目的libs文件夹中。显然,这造成了重复问题。删除后,我的应用程序运行正常。

我天真地这样做是因为我首先在其中使用了Picasso库。我认为这是标准做法。

关于android - 尝试使用Glide包构建Android项目时,抛出 "Unable to merge dex"错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47086275/

10-12 05:26