[android] Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

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'
}

The answer is


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.


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


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.


I solved similar error by adding following piece of code to my build.gradle file inside the android block.

android {
    dexOptions {
        preDexLibraries = false
    }
}

I resolved all of my issues by adding this into project.properties

cordova.system.library.7=com.android.support:appcompat-v7:27.1.0

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


Finally, I solved it modifiying these attributes on the module gradle file

  1. compileSdkVersion 25
  2. targetSdkVersion 25
  3. compile 'com.android.support:appcompat-v7:+'
  4. compile 'com.android.support:recyclerview-v7:+'

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 removed compile 'com.android.support:support-v4:18.0.+' in dependencies, and it works


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 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'

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


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


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


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:

step 1

Second you will see something like this :

Step 2

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:

first

Second:

second

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).


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..


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 :-)


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, 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 :

enter image description here


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


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')

}


Deleting all files from Gradle cache fixed my problem.

on Linux:

rm -rf ~/.gradle/caches/*

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".


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-support-library

No resource found that matches the given name: attr 'android:keyboardNavigationCluster'. when updating to Support Library 26.0.0 Failed to resolve: com.android.support:cardview-v7:26.0.0 android Setting up Gradle for api 26 (Android) How to make ConstraintLayout work with percentage values? Cannot resolve symbol HttpGet,HttpClient,HttpResponce in Android Studio Change EditText hint color when using TextInputLayout Cannot resolve symbol AppCompatActivity - Support v7 libraries aren't recognized? Error inflating class android.support.design.widget.NavigationView FloatingActionButton example with Support Library How to use and style new AlertDialog from appCompat 22.1 and above

Examples related to android-gradle-plugin

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries Invoke-customs are only supported starting with android 0 --min-api 26 error: resource android:attr/fontVariationSettings not found Exception : AAPT2 error: check logs for details Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)