Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using buildToolsVersion 23 fails because Multiple dex files define 'AnimRes'

Before you claim DUPLICATE please read the question.

This only occurs with the latest version of the build tools. Older versions do not display this problem. I've already tried the solutions offered on other questions here for multiple definitions of @AnimRes. None have helped so far, which is why I posted a new question. Same symptoms, different cause, different solution.

I can build without problem when using buildToolsVersion 22.0.1, but when I switch to buildToolsVersion 23 the build fails with error

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106)

This is a list of my dependencies:

provided 'org.projectlombok:lombok:1.16.4'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v13:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:palette-v7:23.0.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.google.guava:guava:18.0'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-io:commons-io:2.4'
compile 'commons-codec:commons-codec:1.10'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup:otto:1.3.8'
compile 'org.jsoup:jsoup:1.7.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.okio:okio:1.5.0'
compile 'com.flaviofaria:kenburnsview:1.0.6'
compile 'com.edmodo:cropper:1.0.1'
compile 'com.getbase:floatingactionbutton:1.10.0'
compile 'com.nispok:snackbar:2.10.10'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.2'
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'de.hdodenhof:circleimageview:1.3.0'

To ensure everyone (including Espresso) uses the same version of the support-annotations I have the following in my build file:

configurations.all {
  resolutionStrategy.force 'com.android.support:support-annotations:23.0.0'
}

Removing this will cause other failures.

Is this a possible bug in the build tools or am I doing something wrong? I've tried setting Incremental false in dexOptions. It didn't help.

Using ./gradlew -q app:dependencies I get the following:

+--- com.android.support:support-v4:23.0.0
|    \--- com.android.support:support-annotations:23.0.0
+--- com.android.support:appcompat-v7:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.android.support:support-v13:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.android.support:cardview-v7:23.0.0
+--- com.android.support:palette-v7:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.google.code.findbugs:jsr305:2.0.1
+--- com.google.guava:guava:18.0
+--- com.github.chrisbanes.photoview:library:1.2.3
|    \--- com.android.support:support-v4:19.+ -> 23.0.0 (*)
+--- org.apache.commons:commons-lang3:3.4
+--- commons-io:commons-io:2.4
+--- commons-codec:commons-codec:1.10
+--- com.jakewharton:butterknife:7.0.1
+--- com.squareup:otto:1.3.8
+--- org.jsoup:jsoup:1.7.2
+--- com.squareup.picasso:picasso:2.5.2
+--- com.squareup.retrofit:retrofit:1.9.0
|    \--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp:2.4.0
|    \--- com.squareup.okio:okio:1.4.0 -> 1.5.0
+--- com.squareup.okhttp:okhttp-urlconnection:2.4.0
|    \--- com.squareup.okhttp:okhttp:2.4.0 (*)
+--- com.squareup.okio:okio:1.5.0
+--- com.flaviofaria:kenburnsview:1.0.6
+--- com.edmodo:cropper:1.0.1
+--- com.getbase:floatingactionbutton:1.10.0
|    \--- com.android.support:support-annotations:22.2.0 -> 23.0.0
+--- com.nispok:snackbar:2.10.10
|    +--- com.android.support:recyclerview-v7:22.0.0
|    |    +--- com.android.support:support-v4:22.0.0 -> 23.0.0 (*)
|    |    \--- com.android.support:support-annotations:22.0.0 -> 23.0.0
|    \--- com.android.support:support-annotations:22.0.0 -> 23.0.0
+--- com.github.ksoichiro:android-observablescrollview:1.5.2
|    \--- com.android.support:recyclerview-v7:21.0.0 -> 22.0.0 (*)
+--- in.srain.cube:grid-view-with-header-footer:1.0.12
\--- de.hdodenhof:circleimageview:1.3.0
like image 434
copolii Avatar asked Aug 18 '15 18:08

copolii


2 Answers

Update: This is fixed in the 23.0.1 version of build tools as the support directory is no longer included in renderscript-v8.jar

The culprit is the version of renderscript-v8.jar that is included in the build tools.

I think this tree output tells everything:

C:.
├───renderscript-v8-22.0.01
│   ├───android
│   │   └───support
│   │       └───v8
│   │           └───renderscript
│   └───META-INF
└───renderscript-v8-23
    ├───android
    │   └───support
    │  ***  ├───annotation
    │       └───v8
    │           └───renderscript
    └───META-INF

I've tagged the directories with the version of the build tools that included them. Notice the annotations subdirectory in renderscript-v8-23 that doesn't exist in renderscript-v8-22.0.01.

There is already a report of the issue here: https://code.google.com/p/android/issues/detail?id=179493 And a duplicate here: https://code.google.com/p/android/issues/detail?id=181697

like image 119
copolii Avatar answered Oct 23 '22 17:10

copolii


I can't say I understand this solution - or that it's necessarily a good fix, but it got my app compiling again:

configurations.all {
    exclude group: 'com.android.support', module: 'support-annotations'
}

Also, see: Getting Multiple dex error when using render script support lib

Credit to Luboš Staráček for this solution

like image 6
Tim Malseed Avatar answered Oct 23 '22 16:10

Tim Malseed