If I run gradle assembleDebug
from the command line, I am suddenly getting this error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.util.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:592)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:550)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:531)
at com.android.dx.merge.DexMerger.mergeDexBuffers(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:186)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:300)
at com.android.dx.command.dexer.Main.run(Main.java:232)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
If I grep for v4 I see two files inside my build folder.
Binary file build/pre-dexed/debug/support-v4-19.0.0-2ba5fdd60a6c3836b3104a863fe42897da1fa9d1.jar matches
Binary file build/pre-dexed/debug/support-v4-r7-227d905d79b23b20866531d4f700446c040a2ccb.jar matches
My gradle file includes only this support library:
compile 'com.android.support:support-v13:19.0.0'
I am stumped as to how the r7 library is included somehow. I've run gradle clean
and it always appears there when I rerun assembleDebug.
If I grep for r7 inside the build directory, I see it inside the file:
Binary file build/exploded-bundles/ComGoogleAndroidGmsPlayServices4030.aar/classes.jar matches
If I don't include v13, then other things don't compile.
But doesn't v13 include v4 support library?
Is this an incompatibility between play services AAR bundle and the v13 library?
I grabbed the gradle file from gradleplease.appspot.com.
Removing play services does not fix it; same error.
My dependencies inside build.gradle:
dependencies {
// Google Play Services
//compile 'com.google.android.gms:play-services:4.0.30'
// Support Libraries
//compile 'com.android.support:support-v4:19.0.0'
///compile 'com.android.support:appcompat-v7:19.0.0'
//compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:support-v13:19.0.0'
compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
compile 'commons-codec:commons-codec:1.9'
compile 'com.madgag:markdownj-core:0.4.1'
compile 'com.wu-man:android-oauth-client:0.0.2'
compile 'com.google.http-client:google-http-client-jackson2:1.17.0-rc'
compile 'org.apache.commons:commons-lang3:3.2'
compile 'com.google.code.gson:gson:2.2.4'
}
I started getting this error when upgrading to ButterKnife 8.5.1. None of the other answers here worked for me.
I used
gradle -q :app:dependencies
to see the tree, and then looked through jar files until I found the conflict. The conflict was that butterknife's dependency oncom.android.support:support-compat:25.1.0
contains a version of the accessibility class, andcom.android.support:support-v4:23.1.1
also contains the class.I solved it by changing my dependency from this:
to this:
It doesn't seem to affect ButterKnife's operation so far.
Edit: There is a better solution, which was to upgrade my android support libraries to match ButterKnife's:
Would not work for me with a project dependency, the only way I could get it to work was via the following syntax:
Where :Android-SDK is your project name.
Since A picture is worth a thousand words
To make it easier and faster to get this task done with beginners like me. this is the screenshots that shows the answer posted by @edsappfactory.com that worked for me:
First open the Gradle view on the right side of Androidstudio, in your app's item go to
Tasks
thenAndroid
then right-clickandroidDependencies
then chooseRun
:Second you will see something like this :
The main reason i posted this that it was not easy to know where to execute a
gradle
task or the commands posted above. So this is where to excute them as well.SO, to execute gradle command:
First:
Second:
Easy as it is.
Thats it.
Thank you.
In Android Studio, go to your build.gradle (check both project and modules build.gradle files) and search for duplicate dependencies.
Delete those your project does not need.
I had the same problem when adding
react-native-palette
to my project, here is my dependencies tree:I tried many solutons and could not fix it, until changing the
com.android.support:appcompat
version inandroid/app/build.gradle
, I wish this can help:it seems that multiple entries is not a big problem, version mismatch is
This is an annoying problem, that can take some time to find out the root case. The way you should proceed is @CommonsWare answer.
I faced this problem recently and found it hard to resolve.
My problem was i was including a library by "+" version in build.gradle. Latest version of library contained one of older dex and bang.
I reverted to older version of library and solved it.
It is good to run your androidDependencies and see what is really happening. Its also good to search in your build folder.
Above all Android Studio 2.2 provide in build features to track this problem.
Happy Coding Guys