How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

cover from https://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility

|

176

down votefavorite

85

|

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

[
image

android](https://stackoverflow.com/questions/tagged/android "show questions tagged 'android'")

gradle

android-support-library

android-gradle

|

share

improve this question

|

[edited

Jan 13 '14 at 19:08](https://stackoverflow.com/posts/20989317/revisions "show all edits to this post")

image

CommonsWare

687k

117

1666

1716

|

asked

Jan 8 '14 at 7:20

image

xrd

1,672

4

17

21

|

|
| |

|

|

1

| |

|

I tried all the solutions, and It happened all of them didn't work. Than I just created a new project with the same name, and copied all the files from the old project. And It works great now. Hope it helps.

– Sam003

Mar 25 '15 at 20:01

|

add a comment

|

21 Answers

activeoldestvotes

|

up vote

263

down vote

accepted

|

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

|

share

improve this answer

|

[edited

Nov 17 '14 at 16:35](https://stackoverflow.com/posts/21100040/revisions "show all edits to this post")

|

answered

Jan 13 '14 at 19:47

image

CommonsWare

687k

117

1666

1716

|

|
| |

|

|

3

| |

|

Is there a method for inspecting/excluding modules from .jar dependencies not available on Maven?

gradle dependencies

seems to not report dependencies added with

compile files('libs/example.jar')

– dbro

Jan 21 '14 at 20:47

|
|

|

3

| |

|

Let's say I have two

libs/*.jar

dependencies with a module in common, neither is available as an artifact. Any way to perform a similar dependency inspection / class exclusion?

– dbro

Jan 21 '14 at 20:59

|
|

|

2

| |

|

@dbro: Not that I am aware of, but, then again, I have not researched this point. IMHO, off the cuff, one or both of those JAR files feel mis-packaged, as the module in common should be factored out into its own JAR.

– CommonsWare

Jan 21 '14 at 21:15

|
|

|

10

| |

|

./gradlew -q :projectName:dependencies worked for me

– Defuera

Nov 17 '14 at 16:28

|
|

|

14

| |

|

Quick tip for those exlucing a module from a module dependency: You have to turn your

compile project(':foo')

into

compile(project(':foo')) { exclude module: 'support-v4' }. Note the parenthesis.

– espinchi

Nov 22 '14 at 17:28

|

[show

25

more comments](https://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility# "expand to show all comments on this post")

|

|

up vote

108

down vote

|

I solved similar error by adding following piece of code to my

build.gradle

file inside the android block.

android {
    dexOptions {
        preDexLibraries = false
    }
}

|

share

improve this answer

|

[edited

Jan 21 '16 at 0:26](https://stackoverflow.com/posts/24025291/revisions "show all edits to this post")

image

Sebas Hollow

85

7

|

answered

Jun 3 '14 at 21:32

image

mike.tihonchik

3,732

3

21

34

|

|
| |

|

|

4

| |

|

Worked for me! Is there any down sides of doing it this way?

– Barrie Galitzky

Jul 23 '14 at 5:00

|
|

| | |

|

@BarrieGalitzky I haven't ran into any issues so far

– mike.tihonchik

Jul 23 '14 at 13:13

|
|

|

3

| |

|

Thanks man, this worked perfectly to solve the issue! Anyway, I think that it has some side effects.. The assembleDebug task became 3 times slower!

– marino

Oct 23 '14 at 0:40

|
|

|

5

| |

|

Wondering what @CommonsWare would have to say about this solution...

– treesAreEverywhere

Aug 28 '15 at 18:16

|
|

|

2

| |

|

After adding this, I got "Translation has been interrupted" error. Guess I've to give CommonsWare method a try.

– DroidHeaven

May 20 at 9:26

|

[show

9

more comments](https://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility# "expand to show all comments on this post")

|

|

up vote

32

down vote

|

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

|

share

improve this answer

|

answered

Apr 30 '14 at 15:20

image

edsappfactory.com

359

3

7

|

|
| |

|

|

3

| |

|

More specific instruction? Can't find "androidDependencies". Thx

– CopperCash

Jul 9 '14 at 2:37

|
|

| | |

|

Go to the Gradle view, then find the heading All tasks, drill down on your app's name, then drill down on ":app", you will find "androidDependencies" there.

– AutoM8R

Dec 7 '14 at 20:08

|
|

|

1

| |

|

Where is the Gradle view?

– Paul Beusterien

Feb 4 '15 at 22:08

|
|

|

3

| |

|

@PaulBeusterien If you look to the far right side of the window, there's a sideways tab marked Gradle. Click it to open a pinned view. The androidDependencies is actually a gradle task

– JCricket

Feb 5 '15 at 16:01

|
|

| | |

|

thank you man, i posted screenshots explaining your answer to make it easier.

– MBH

Jan 18 '16 at 9:37

|

add a comment

|

|

up vote

23

down vote

|

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:

How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat_第1张图片
step 1

Second

you will see something like this :

How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat_第2张图片
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:

How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat_第3张图片
first

Second:

How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat_第4张图片
second

Easy as it is.

Thats it.

Thank you.

|

share

improve this answer

|

answered

Jan 18 '16 at 9:36

image

MBH

5,337

8

52

95

|

|
| |

add a comment

|

|

up vote

9

down vote

|

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

|

share

improve this answer

|

[edited

May 23 at 11:33](https://stackoverflow.com/posts/30297509/revisions "show all edits to this post")

image

Community

1

1

|

answered

May 18 '15 at 7:36

[图片上传失败...(image-e501b4-1511851863363)]

Tony Thompson

106

2

8

|

|
| |

|

| | |

|

Thanks, was missing double parenthesis!

– Marko

Jul 7 '15 at 10:59

|

add a comment

|

|

up vote

7

down vote

|

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.

|

share

improve this answer

|

answered

Jul 9 '15 at 6:18

[图片上传失败...(image-a9218f-1511851863363)]

Pellet

836

12

12

|

|
| |

add a comment

|

|

up vote

6

down vote

|

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'

|

share

improve this answer

|

[edited

Feb 22 at 18:16](https://stackoverflow.com/posts/42381058/revisions "show all edits to this post")

|

answered

Feb 22 at 1:27

image

user3562927

251

5

11

|

|
| |

|

| | |

|

keep the support version to be same is simple solution and exclude module is not work for me.

– Jay

Mar 16 at 9:19

|
|

|

1

| |

|

I solved with th second solution, thank you!

– Mitro

Mar 16 at 10:48

|

add a comment

|

|

up vote

5

down vote

|

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

|

share

improve this answer

|

[edited

Aug 9 at 11:50](https://stackoverflow.com/posts/31673865/revisions "show all edits to this post")

image

cricket_007

52.8k

7

28

69

|

answered

Jul 28 '15 at 10:36

image

voghDev

2,063

17

26

|

|
| |

add a comment

|

|

up vote

4

down vote

|

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.

|

share

improve this answer

|

answered

Mar 26 '14 at 16:35

image

ashishduh

4,372

2

17

30

|

|
| |

|

|

1

| |

|

Had the same error after upgrading intellij, cleaning the project fixed the issue.

– Vlad Spreys

Apr 25 '14 at 1:51

|

add a comment

|

|

up vote

4

down vote

|

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

|

share

improve this answer

|

answered

Nov 15 '15 at 14:22

image

Giannis P

41

1

|

|
| |

|

|

1

| |

|

Multidexing can make your app start up speed slower, only use it if you really have to.

– James Goodwin

Dec 6 '15 at 14:41

|

add a comment

|

|

up vote

3

down vote

|

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

|

share

improve this answer

|

answered

Nov 20 '16 at 12:48

image

WindRider

6,046

2

34

39

|

|
| |

add a comment

|

|

up vote

3

down vote

|

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.

|

share

improve this answer

|

[edited

Aug 9 at 11:53](https://stackoverflow.com/posts/42851575/revisions "show all edits to this post")

image

cricket_007

52.8k

7

28

69

|

answered

Mar 17 at 7:25

image

shiny vn

51

3

|

|
| |

add a comment

|

|

up vote

2

down vote

|

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

|

share

improve this answer

|

answered

Sep 18 '15 at 16:28

image

MobileEvangelist

1,702

1

11

29

|

|
| |

add a comment

|

|

up vote

2

down vote

|

I'm using

com.google.android.gms:play-services-analytics:8.3.0

and

android-support-v13.jarand 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')

}

|

share

improve this answer

|

answered

Dec 14 '15 at 14:38

image

barry

2,171

2

25

58

|

|
| |

add a comment

|

|

up vote

2

down vote

|

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

|

share

improve this answer

|

answered

Sep 24 '16 at 18:19

image

Arun C

7,913

1

20

34

|

|
| |

add a comment

|

|

up vote

2

down vote

|

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.

|

share

improve this answer

|

[edited

Aug 9 at 11:54](https://stackoverflow.com/posts/28144571/revisions "show all edits to this post")

[图片上传失败...(image-f725da-1511851863362)]

cricket_007

52.8k

7

28

69

|

answered

Jan 26 '15 at 3:50

image

KadoLakatt

35

5

|

|
| |

add a comment

|

|

up vote

1

down vote

|

I removed compile 'com.android.support:support-v4:18.0.+' in dependencies, and it works

|

share

improve this answer

|

answered

Aug 18 '15 at 3:29

image

albert

11

1

|

|
| |

|

|

2

| |

|

this should be a comment or else you should explain it in a better way.

– Anirudh Sharma

Aug 18 '15 at 3:49

|

add a comment

|

|

up vote

1

down vote

|

Deleting all files from Gradle cache fixed my problem.

on Linux:

cd ~/.gradle  
rm -R -f *

|

share

improve this answer

|

answered

Jul 9 '16 at 17:35

image

Iuliia Ashomok

2,833

1

30

33

|

|
| |

add a comment

|

|

up vote

0

down vote

|

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

|

share

improve this answer

|

answered

Mar 16 at 18:13

image

Val Martinez

128

1

8

|

|
| |

add a comment

|

|

up vote

0

down vote

|

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

|

share

improve this answer

|

answered

Jun 4 at 14:03

image

matrixer

1

1

|

|
| |

add a comment

|

|

up vote

0

down vote

|

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.

|

share

improve this answer

|

|

你可能感兴趣的:(How to solve Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat)