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 solved similar error by adding following piece of code to my build.gradle file inside the android block.
I had the same error on a legacy project. My fault was that the support-library was included twice: Once inside google-play-services lib, and another as standalone.
This is how I fixed it:
BAD build.gradle:
GOOD build.gradle:
Hope it helps someone :-)
I'm using
com.google.android.gms:play-services-analytics:8.3.0
andandroid-support-v13.jar
and could not getexclude module: 'support-v4'
to work.What worked for me was using the
android-support-v13
artefact rather than theandroid-support-v13.jar
file.I.e. instead of
}
I used
}
Also to note you can see your android dependencies, by going to your Android Studio Gradle view, and selecting the target "androidDependencies".
One more tip: I was having this issue, until I removed the v4 support lib from the libs folder in both the project and my related module/library project(s).
A similar dex issue resolved method
gradle.build was containing:
The issue was resolved when i removed
My gradle now looks like:
There was a redundancy in the JAR file and the compiled gradle project
So keenly look for dependency and jar files having same classes.
And remove redundancy.
This worked for me.
I've had the same issue. In my project, I had the following dependencies :
For legacy reasons, the appcompat was fetched from the Google Maven repo, whereas the android-support was a local .jar.
When I figured out this, and replaced this local reference with a maven reference, it just solved my build issue.
Here's the diff of my app/build.gradle :