本文介绍了Android Gradle插件3.0.0:多个dex文件使用XStream定义了Lorg/xmlpull/mxp1/MXParser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自带的xmlpullparser包含的项目在Android Studio中始终需要格外小心,因为Android自带了xmlpullparser.

Included projects that bring their own xmlpullparser always needed some extra care in Android Studio since Android brings its own xmlpullparser.

例如流行的XML映射器XStream要求此排除 (1) (2):

E.g. the popular XML mapper XStream required this exclude (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插件版本)

The news on this question is: The exclude worked on Android Plugin Version 2.3.3 while on Android Plugin Version 3.0.0 I get errors again! (You can see the Android Plugin Version under File > Project Structure > Project)

是否有人已经知道如何更改gradle文件以使xstream在 Android插件版本3.0.0 ?

Has anybody already figured out how to change the gradle file to get xstream running on Android Plugin Version 3.0.0?

我只是怀疑"XStream"会导致该错误.

It's just my suspicion that 'XStream' causes that error.


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插件版本.

Finally I found the fix. However, I am still puzzled why it depended on the Gradle Plugin Version.

我使用的 logback-android 依赖图:

    +--- 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,然后使用implementation project(:'myUtilsModule')

It must be said that I declared logback-android in a utils module which I then included into my app using implementation project(:'myUtilsModule')

现在,我排除了组xpp3及其模块xpp3.组和模块名称xmlpull不起作用.

Now I excluded the group xpp3 with its module xpp3. The group and module names xmlpull wouldn't work.:

// 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
}

我学习了如何读取依赖关系图以及如何从图中排除项目的艰难方法;)

I learnt the hard way how to read the dependency graph and how to exclude items from the graph ;)

  1. 运行如何在Android Studio中显示依赖关系树?
  2. 依赖关系图中的每一行都具有以下格式:<group>:<module>:<version>
  3. 映射到排除参数exclude group: '<group>', module: '<module>'或仅exclude module: '<module>'
  1. Run How do I show dependencies tree in Android Studio?
  2. Each line in the dependency graph has the format<group>:<module>:<version>
  3. which maps to the exclude argumentsexclude group: '<group>', module: '<module>' or just exclude module: '<module>'

更新:使用登录-android-1.1.1-7 + 不再需要排除.

Update: With logback-android-1.1.1-7+ the exclude is no longer necessary.

这篇关于Android Gradle插件3.0.0:多个dex文件使用XStream定义了Lorg/xmlpull/mxp1/MXParser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:24