androidandroid-gradle-pluginxstreamandroid-buildxmlpullparser

Android Gradle Plugin 3.0.0: Multiple dex files define Lorg/xmlpull/mxp1/MXParser with XStream


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

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
}

Somewhere else I also have seen:

compile('com.thoughtworks.xstream:xstream:1.4.7') {
      exclude group: 'xmlpull'
     exclude group: 'XmlPullParser'
  }

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)

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

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

Solution

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

    I am using logback-android that somehow depends on xpp3 as you can see on the dependency graph:

        +--- 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
    

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

    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. 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 arguments exclude group: '<group>', module: '<module>' or just exclude module: '<module>'

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