com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

穿精又带淫゛_ 提交于 2019-11-30 14:20:00

Your problem i believe is that wherever you are linking the Library to your Main Project you have the same dependencies between the two for your support library and annotations.

If you have the library project as a dependency in your application you will only need the dependency to be placed in the library dependencies closure.

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

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

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

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

For your library's build.gradle

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 project build.gradle

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

Since facebook sdk configed for using Android 2.3.3, it requires annotaion lib. My app configed for using Anndoid > 4.x.x, which is contains Annotation, the conflict was emarged. I have changed, in the facebbok mainfest, to work with Android > 4.x.x and it solved the problem.

if you migrate the project from eclipse to studio , and then your project need a new module, you add the build.gradle which in the module, add the dependencies like this,

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 might be see this stupid problem because the old project has include the jar file like android-support-v4.jar this shit is overlay the compile(thing) so you must remove the *.jar file, this shit takes my hole afternoon, so good luck ,my english is pool, fogiven me please

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

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

I removed the reference to v4 like below

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

I cleaned the project and was able to build my APK. I don't know if this was the correct way to fix it but it worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!