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'
}
Run gradle -q dependencies
(or gradle -q :projectName:dependencies
) to generate a dependency report. You should see where r7
is coming from, such as:
compile - Classpath for compiling the main sources.
+--- com.commonsware.cwac:camera-v9:0.5.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| | \--- com.google.android:support-v4:r7
| +--- com.commonsware.cwac:camera:0.5.4
| \--- com.android.support:support-v4:18.0.+ -> 18.0.0
\--- com.android.support:support-v4:18.0.+ -> 18.0.0
Then, use the exclude
directive to block that dependency. In my case, it is coming from my CWAC-Camera library, and so I use:
dependencies {
compile('com.commonsware.cwac:camera-v9:0.5.4') {
exclude module: 'support-v4'
}
compile 'com.android.support:support-v4:18.0.+'
}
(where the second compile
statement indicates what version you actually want)
That should clear matters up, as you will see if you run the dependency report again:
compile - Classpath for compiling the main sources.
+--- com.commonsware.cwac:camera-v9:0.5.4
| +--- com.actionbarsherlock:actionbarsherlock:4.4.0
| \--- com.commonsware.cwac:camera:0.5.4
\--- com.android.support:support-v4:18.0.+ -> 18.0.0
I solved similar error by adding following piece of code to my build.gradle file inside the android block.
android {
dexOptions {
preDexLibraries = false
}
}
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
then Android
then right-click androidDependencies
then choose Run
:
https://i.stack.imgur.com/DPJkT.png
Second you will see something like this :
https://i.stack.imgur.com/n5Klg.png
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:
https://i.stack.imgur.com/louca.png
Second:
https://i.stack.imgur.com/eThSB.png
Easy as it is.
Thats it.
Thank you.
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).
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 on com.android.support:support-compat:25.1.0
contains a version of the accessibility class, and com.android.support:support-v4:23.1.1
also contains the class.
I solved it by changing my dependency from this:
compile 'com.jakewharton:butterknife:8.5.1'
to this:
compile('com.jakewharton:butterknife:8.5.1') {
exclude module: 'support-compat'
}
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:
compile('com.android.support:appcompat-v7:25.2.0')
compile('com.android.support:design:25.2.0')
compile 'com.jakewharton:butterknife:8.5.1'
In case anyone finds out that the answer from CommonsWare could not be applied to android library project, here is the snippet to fix
compile (project(':yourAndroidLibrary')){ exclude module: 'support-v13' }
You will find problems
Unsupported Gradle DSL method found: 'exclude()'
if you use compile project(':yourAndroidLibrary'){ exclude module: 'support-v13' }
The differences are the bracelet "(" and ")" before "project".
exclude module: 'support-v4'
Would not work for me with a project dependency, the only way I could get it to work was via the following syntax:
configurations {
dependencies {
compile(project(':Android-SDK')) {
compile.exclude module: 'support-v4'
}
}
}
Where :Android-SDK is your project name.
I had the same problem and it seems that my app had too many methods because of the libraries: http://developer.android.com/tools/building/multidex.html
Solved it with:
android {
defaultConfig {
...
multiDexEnabled = true
}
}
More here Error:Execution failed for task ':app:dexDebug'. > comcommand finished with non-zero exit value 2
I had this same error but it was because I had recently changed from using v4 to v13. So all I had to do was clean the project.
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:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/core-2.2.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile 'com.google.android.gms:play-services:3.2.65'
}
GOOD build.gradle:
dependencies {
// compile files('libs/android-support-v4.jar') // not needed
compile files('libs/core-2.2.jar')
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
compile 'com.google.android.gms:play-services:3.2.65'
}
Hope it helps someone :-)
I'm using com.google.android.gms:play-services-analytics:8.3.0
and android-support-v13.jar
and could not get exclude module: 'support-v4'
to work.
What worked for me was using the android-support-v13
artefact rather than the android-support-v13.jar
file.
I.e. instead of
dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile files('libs/android-support-v13.jar')
}
I used
dependencies {
compile ('com.google.android.gms:play-services-analytics:8.3.0')
compile ('com.google.android:android-support-v13')
}
In my case the problem was caused by version inconsistency:
Build tools 25
compileSdk 24
targetSdk 24
Support library 24
The solution was simple: Make everything version 25
A similar dex issue resolved method
gradle.build was containing:
compile files('libs/httpclient-4.2.1.jar')
compile 'org.apache.httpcomponents:httpclient:4.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
The issue was resolved when i removed
compile files('libs/httpclient-4.2.1.jar')
My gradle now looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.mmm.ll"
minSdkVersion 16
targetSdkVersion 24
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:6.1.+'
compile files('libs/PayPalAndroidSDK.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar')
compile files('libs/picasso-2.1.1.jar')
compile files('libs/gcm.jar')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
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.
If you have imported your project from Eclipse.
1. The select project
2. Go to File -> **Project Structure**
3. Select app in **module** section on left hand panel
4. Select **Dependency** tab
5. Your able to see jars you have added in eclipse project for v4 and v13.
6. Remove that jar by clicking on minus sign at bottom after selection
7. Click on Plus sign select **Library Dependency**
8. Choose V4 and V13 if added
9. Press Ok and Clean and Rebuild your project
The scenario I have faced after importing Eclipse project to Android studio.
Hope this helps..
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
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.
Deleting all files from Gradle cache fixed my problem.
on Linux:
rm -rf ~/.gradle/caches/*
I removed compile 'com.android.support:support-v4:18.0.+' in dependencies, and it works
I was able to solve the problem in my react native project by simply adding
configurations {
all*.exclude group: 'com.android.support', module: 'support-compat'
all*.exclude group: 'com.android.support', module: 'support-core-ui'
}
at the end of my android\app\build.gradle file
Finally, I solved it modifiying these attributes on the module gradle file
compileSdkVersion 25 targetSdkVersion 25 compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:recyclerview-v7:+'
I had the same problem when adding react-native-palette
to my project, here is my dependencies tree:
./gradlew app:dependencies
+--- project :react-native-palette
| +--- com.facebook.react:react-native:0.20.+ -> 0.44.2
| | +--- javax.inject:javax.inject:1
| | +--- com.android.support:appcompat-v7:23.0.1
| | | \--- com.android.support:support-v4:23.0.1
| | | \--- com.android.support:support-annotations:23.0.1 -> 24.2.1
...
| \--- com.android.support:palette-v7:24.+ -> 24.2.1
| +--- com.android.support:support-compat:24.2.1
| | \--- com.android.support:support-annotations:24.2.1
| \--- com.android.support:support-core-utils:24.2.1
| \--- com.android.support:support-compat:24.2.1 (*)
+--- com.android.support:appcompat-v7:23.0.1 (*)
\--- com.facebook.react:react-native:+ -> 0.44.2 (*)
I tried many solutons and could not fix it, until changing the com.android.support:appcompat
version in android/app/build.gradle
, I wish this can help:
dependencies {
compile project(':react-native-palette')
compile project(':react-native-image-picker')
compile project(':react-native-camera')
compile fileTree(dir: "libs", include: ["*.jar"])
// compile "com.android.support:appcompat-v7:23.0.1"
compile "com.android.support:appcompat-v7:24.2.1"
compile "com.facebook.react:react-native:+"
}
it seems that multiple entries is not a big problem, version mismatch is
Got it working for a compile file('...')
conflict by increasing minSdkVersion to 21 and enabling multidex. Not sure if that is the best solution but the only way I could get it working in my case.
Note: for compile file('...')
it appears that you cannot put in an exclude
clause so that option was not available.
I had the same problem, and my solution is changing the support version '27.+'(27.1.0) to '27.0.1'
I've had the same issue. In my project, I had the following dependencies :
appcompat-v7
android-support-v13
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 :
https://i.stack.imgur.com/oqMdB.jpg
I resolved all of my issues by adding this into project.properties
cordova.system.library.7=com.android.support:appcompat-v7:27.1.0
Received the following error
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Landroid/support/constraint/ConstraintSet$1
Fix : go to Build -> Clean Project
Success story sharing
gradle dependencies
seems to not report dependencies added withcompile files('libs/example.jar')
libs/*.jar
dependencies with a module in common, neither is available as an artifact. Any way to perform a similar dependency inspection / class exclusion?compile project(':foo')
intocompile(project(':foo')) { exclude module: 'support-v4' }
. Note the parenthesis.