由于Android自带了自己的xmlpullparser,因此包含的项目在Android Studio中总是需要额外小心。
E、 g.流行的XML映射器XStream要求排除(1)(2):
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull' //exclude xmlpull to avoid `Multiple dex files define`-error
}
在别的地方我也见过:
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull'
exclude group: 'XmlPullParser'
}
关于这个问题的新闻是:排除在Android插件版本2.3.3上工作,而在Android插件版本3.0.0上,我再次出错!(你可以在文件下看到Android插件版本
有人已经想出了如何更改gradle文件以使xstream在Android插件3.0.0版本上运行吗?
我只是怀疑“XStream”导致了这个错误。
16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is: 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100) 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63) 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 16:40:26.671 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124) 16:40:26.672 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:72) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: com.android.dex.DexException: Multiple dex files define Lorg/xmlpull/mxp1/MXParser; 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661) 16:40:26.673 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616) 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598) 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.dx.merge.DexMerger.merge(DexMerger.java:198) 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61) 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] ... 1 more 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 16:40:26.674 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 37s
最后我找到了解决办法。然而,我仍然不明白为什么它依赖于Gradle插件版本。
我使用的是logback android,它在某种程度上依赖于xpp3,如依赖关系图所示:
+--- com.github.tony19:logback-android-classic:1.1.1-6
| | +--- com.github.tony19:logback-android-core:1.1.1-6
| | \--- com.github.tony19:apktool-lib:1.4.4-3
| | \--- com.google.android:android:2.1_r1
| | +--- commons-logging:commons-logging:1.1.1
| | +--- org.apache.httpcomponents:httpclient:4.0.1
| | | +--- org.apache.httpcomponents:httpcore:4.0.1
| | | +--- commons-logging:commons-logging:1.1.1
| | | \--- commons-codec:commons-codec:1.3
| | +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
| | +--- xerces:xmlParserAPIs:2.6.2
| | \--- xpp3:xpp3:1.1.4c
必须指出的是,我在一个utils模块中声明了logback android,然后使用实现项目(:'myUtilsModule')将其包含在我的应用程序中
现在我排除了带有模块xpp3的组。组和模块名称无法工作:
// https://mvnrepository.com/artifact/com.github.tony19/logback-android-classic
implementation('com.github.tony19:logback-android-classic:1.1.1-6') {
exclude group: 'xpp3', module: 'xpp3' //in order to avoid "Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;"
//exclude group: 'xmlpull', module: 'xmlpull' //This works usually on other libs to exclude xmlpull, but not on that one
}
我学会了如何阅读依存关系图以及如何从图中排除项目;)
更新:对于logback-android-1.1.1-7,不再需要排除。
问题内容: 我知道这个问题已经在这里问过几次了。但是我还没有看到任何可能的解决方案。在我将项目“以Android应用程序身份运行”之前,如果我不清理它,则会收到以下错误,并且必须重新启动Eclipse …并再次清理。 com.jstun.core …是我的src文件夹的一部分,我当然不能删除它。即使我删除该程序包,另一个程序包也会显示为错误,例如: 自更新为ADT 15以来,我已经看到此错误,我正
我无法编译该项目,编译时出现以下错误: 错误:任务': myApp: dexDebug'执行失败。 通用域名格式。Android石斑鱼类。常见的内部的LoggedErrorException:无法运行命令:C:\Program Files(x86)\Android\Android studio\sdk\build tools\21.0.2\dx。bat--dex--输出C:\Users\Andro
我遇到了Firebase集成的问题。首先,我在根级别文件: 和模块梯度文件: 在项目的构建过程中,我得到了以下错误: 错误:将字节码转换为dex:Cause:com时出错。Android德克斯。DexException:多个dex文件定义Lcom/google/firebase/FirebaseException; 错误原因很清楚,但我没有编译任何库两次。我是否应该手动从构建过程中排除类?如果是,
我敢肯定,不知怎么的,我添加了两倍的谷歌库。 多谢了。
当我将android支持注释添加到我的依赖项时 我有一个错误: 错误代码:2输出:意外的顶级异常:com.android.dex.dexException:多个dex文件定义Landroid/Support/Annotation/Animres;在com.android.dx.merge.dexmerger.readsortabletypes(dexmerger.java:594)在com.and