Multiple dex files define landroid / support / annotation / AnimRes

The moment I added android support annotations to my dependencies

compile 'com.android.support:support-annotations:20.0.0'

I got this error:

Error code: 2 Exit: UNCERTAIN TOP LEVEL EXCLUSION: com.android.dex.DexException: several dex files define Landroid / support / annotation / AnimRes; at com.android.dx.merge.DexMerger.readSortableTypes (DexMerger.java∗94) at com.android.dx.merge.DexMerger.getSortedTypes (DexMerger.java UP52) on com.android.dx.merge.DexMerger.mergeClassDefs (DexMerger.java∗33) on com.android.dx.merge.DexMerger.mergeDexes (DexMerger.java:170) on com.android.dx.merge.DexMerger.merge (DexMerger.java:188) on com.android. dx.command.dexer.Main.mergeLibraryDexBuffers (Main.java:439) on com.android.dx.command.dexer.Main.runMonoDex (Main.java:287) on com.android.dx.command.dexer.Main. run (Main.java:230) on com.android.dx.command.dexer.Main.main (Main.java:199) on com.android.dx.command.Main.main (Main.java:103)

build.gradle

 android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 10 targetSdkVersion 19 } } dependencies { compile 'com.android.support:support-v4:19.0.0' compile 'com.crashlytics.android:crashlytics:1.+' compile 'com.android.support:support-annotations:20.0.0' } 

Has anyone else experienced this issue? I have tried the solutions from here .

+54
java android
Oct 13 '14 at 2:30 p.m.
source share
18 answers

The problem is that android-support-annotations.jar used as a separate library containing android annotations, but for some reason these annotations are already included in the latest versions of android-support-v4.jar .

Removing annotations helped solve the problem.

+65
Nov 03 '14 at 12:06
source share

Build-> clean Project and it worked

+30
Mar 24 '15 at 7:44
source share

I uninstalled android-support-v4.jar and it worked.

+20
Dec 12 '14 at 3:30
source share

If this is a cordova / ionic project, it worked for me

add this line to build.gradle under / android platforms after line number 22 ie after apply the plugin: 'android'

 configurations { all*.exclude group: 'com.android.support', module: 'support-v4' } 
+8
Feb 02 '16 at 6:45
source share

Solved this exact problem in a Cordova project that used the facebook plugin. I was able to successfully build by commenting this line from platforms\android\project.properties , as shown:

 # cordova.system.library.1=com.android.support:support-v4:+ 

And, commenting out this line from platforms\android\build.gradle , as shown:

 // compile "com.android.support:support-v4:+" 

Then complete the assembly. The problem arose when I installed (katzer / cordova-plugin-local-notifications), which added these lines, but created a conflict, because the library that it added to the assembly was already part of the facebook plugin assembly.

+7
Oct 12 '15 at 18:12
source share

As other users have said, the first elements for troubleshooting are dependencies. Although sometimes you can fight for several hours and you will not find any problems, so you can focus on the assembly process.

Changing the way you create .dex files sometimes solves the problem. You can follow these steps:

  • Open the Build.gradle file (application)
  • Search for dexOptions task
  • Change it to:

     dexOptions { incremental false } 

If you do not find the task in your file, you can add it.

+3
Aug 17 '15 at 20:45
source share

I had the same problem, but I deleted the build files from the build folder

project_name / application / assembly

and he removed all the related error. "cannot clear the project", as well as "dex errow with $ anim"

+2
Jan 02 '15 at 6:37
source share

I managed to fix this problem. The reason was because I included support for 19.0.0 in dependency support, but 19.1.0. See here for more details.

So what it should be

 dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.crashlytics.android:crashlytics:1.+' compile 'com.android.support:support-annotations:20.0.0' } 
+1
Oct 21 '14 at 9:34
source share

If you import AppCompat as a library project and you also have android-support-annotations.jar in libs elsewhere, be sure to import only the library everywhere AppCompat (it already includes this lib annotation). Then remove all android-support-annotations.jar to avoid merging multiple versions of this library.

+1
Jan 07 '15 at 0:16
source share

The Android SDK Tools update fixed this for me, now it just sees a copy in android-support-v4.jar .

I had the same problem when using ant, and the annotation library was automatically included by the deprecated sdk.dir/tools/ant/build.xml .

+1
May 30 '15 at 10:41
source share

A clean project works as a temporary fix, but the problem will reappear on the next compilation error.

To install more reliably, I had to update the dependency on android support-v4 to com.android.support:support-v4:22.2.0 .

+1
Jul 15 '15 at 12:47
source share

For me, the reason was the new lib data binding

 com.android.databinding:dataBinder:1.0-rc2 

it somehow used a contradictory version of lib annotations that I couldn't get with

 configurations.all { resolutionStrategy { force group: 'com.android.support', name: 'support-v4', version: '23.1.0' force group: 'com.android.support', name: 'appcompat-v7', version: '23.1.0' force group: 'com.android.support', name: 'support-annotations', version: '23.1.0' } } 

but the new rc3 and rc4 seem to have fixed it, so just use these versions

+1
Nov 02 '15 at 20:23
source share

Place a support annotation dependency in build.gradle according to your SDKVersion compiler. For example: a project with compileSdkVersion 25, you can install the following dependency:

 compile 'com.android.support:support-annotations:25.0.1' 

This will solve your problem.

+1
Dec 06 '16 at 18:18
source share

In my case, I had a file called cache.xml under /build/intermediates/dex-cache/cache.xml in the root folder of the project. I deleted this file, restored the project and worked for me.

0
Aug 10 '15 at 16:20
source share

I uninstalled android-support-v4.jar and it worked.

Explanation. android-support-v4.jar contradicts my other .jar project files \ libs **, especially when you work with java 8 on AS.

0
Feb 27 '16 at 17:41
source share

Put android-support-v4.jar support in the libs folder in eclipse. Clean and create a project. This will solve the problem.

0
Apr 6
source share

Another reason that such messages may occur in Android Studio when you create and run it may be the reason for application tags in your libraries.

If you have several Android library projects that you have imported as modules. Go to these projects and remove the <application> ... </application> tags and everything in between. This can cause problems during the build process along with the support library problems already mentioned.

0
Oct 17 '16 at 13:36
source share

From / platform / android / libs / remove android-support-v4.jar. This works for me.

0
Mar 29 '17 at 9:12
source share



All Articles