Com.android.dex.DexException: several dex files define Landroid / support / annotation / AnimRes;

Hello, I am working on a project for which I am using Android Studio. I have setup everything, but when I start my project, I get below errors. I have not been able to resolve this in the last 2 days. What could be the problem of my project causing this error?

Please help if anyone knows about this.

app build.gradle

apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "21.1.2" defaultConfig { applicationId "in.xyz" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.+' //compile files('libs/android-support-v4.jar') compile 'com.android.support:support-v4:22.0.+' compile 'com.android.support:support-annotations:20.0.0' } 

build.gradle library

 apply plugin: 'com.android.library' android { compileSdkVersion 22 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 15 targetSdkVersion 22 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { //compile files('libs/android-support-v4.jar') compile 'com.android.support:support-v4:22.0.+' compile 'com.android.support:support-annotations:20.0.0' } 

build.gradle

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } 

...

 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:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106) Error:Execution failed for task ': app:dexDebug'. 

settings.gradle

 include ':app' include ':multiStateToggleButton' 
+6
source share
4 answers

Your problem is that wherever you link the library to the main project, you have the same dependencies between them for your support library and annotations.

If you have a library project as a dependency in your application, you only need the dependency, which will be placed in closing the library dependencies.

The problem is that you have two dex files, because there are two files with the same name, because they overlap in the files with your dependencies.

First copy your module to your libs / main folder of the main project, then

create the settings.gradle file in the root of the main project:

 include 'app_name', 'library_name' project(':LibraryNameGoesHere').projectDir = new File('libs/LibraryNameGoesHere') 

For your build.gradle library

 dependencies { compile files('libs/android-support-v4.jar') compile 'com.android.support:support-v4:22.0.+' compile 'com.android.support:support-annotations:20.0.0' } 

Then for your main build.gradle project

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.+' compile project(":libs:LibraryNameGoesHere") } 
+6
source

Since facebook sdk is configured to use Android 2.3.3, it requires the lib annotation. My application is configured to use Anndoid> 4.xx containing an annotation, a conflict has been released. I changed the work with Android> 4.xx in mainbest facebbok and solved the problem.

+2
source

if you transfer the project from eclipse to the studio, and then your project needs a new module, you will add build.gradle, which will add dependencies similar to this in the module,

 compile 'com.android.support:support-annotations:24.1.1' compile 'com.android.support:support-v4:24.1.1' //recyclerview compile 'com.android.support:cardview-v7:21.0.3' compile 'com.android.support:recyclerview-v7:21.0.3' 

you can see this stupid problem because the old project includes a jar file such as android-support-v4.jar this shit overlaps compilation (thing), so you have to delete the * .jar file, this shit takes my hole in the afternoon, so good luck my english is pool, fogiven me please

0
source

For what it was worth, I got this error after using Android Studio to import a project from Eclipse. In the file /app/build.gradle, I had two entries in the dependency section, it looked like this:

 dependencies { compile files('libs/android-support-v13.jar') compile files('libs/android-support-v4.jar') } 

I removed the link to v4 as shown below

 dependencies { compile files('libs/android-support-v13.jar') } 

I cleaned up the project and was able to build my APK. I don't know if this has been fixed correctly, but it worked for me.

0
source

Source: https://habr.com/ru/post/985116/


All Articles