Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat
Asked Answered
C

26

216

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'
}
Couplet answered 8/1, 2014 at 7:20 Comment(2)
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.Pathogen
I had this issue with a component in support-v13. After much debugging and trying all the answers to no avail, I found out it was introduced when I tried integrating kotlin into the project which was an exsiting java project. I removed the kotlin standard library and other kotlin libraries and it was fine. Would still try to fix the problem with kotlin but for now, I gotta work. Any info would help too, really love kotlin.Glycerite
C
305

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
Cluck answered 13/1, 2014 at 19:47 Comment(27)
Build was broken after I added one new compile statement. gradle -q dependencies has given me nothing, but adding exlusion to compile statement has fixed the problem.Burne
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')Dregs
@dbro: I guess I don't understand your scenario. Are you saying that you have a JAR in libs/ that is also being pulled in via some artifact?Cluck
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?Dregs
@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.Cluck
Sorry I'm a newbie how to run "gradle -q dependencies" I don't know how to find gradle.exeAcquire
@um.anusorn: Sorry, but I can't help you there, as I do not regularly use Windows.Cluck
@Cluck Thank you. I just try to config build.gradle on every modules that needs libs and now I can run my project! ^^Acquire
I had to run the following for the dependencies to print out: ./gradlew -q :<rootdir>:dependenciesAffairs
@um.anusom if you are using Android Studio just select the terminal in the lower left of the programKerrill
@Cluck i've tried to exclude the modules like you wrote, but I get Build script error, unsupported Gradle DSL method found: 'exclude()'! and can't find much about this error. Is this related to gradle settings ?Cobber
@Michael: It is possible it is related to your version of Gradle or the Gradle for Android plugin.Cluck
My main build.gradle file mentions classpath 'com.android.tools.build:gradle:0.9.+' but gradle-wrapper.properties has distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip .Cobber
@Cluck : hello, I followed you, but can not solve the problem. Could u check for me please?Jefe
I just killed a couple of hours trying to fix this. As @Dregs points out, a manually added library will not have its dependencies listed, but unfortunately this "exclude" command seems to be ignored as well. In the end I couldn't exclude support-v4 from the manually added lib, and instead had to exclude it from all my other dependencies acquired from Maven Central.Abduction
@TedAvery: If by "manually added library" you mean "something I put in libs/", then there are no dependencies, from the standpoint of automated dependency management. This is why the Android tools team is steering everyone towards converting those into artifacts in some repository (e.g., local repository, team repository).Cluck
./gradlew -q dependencies should have the same effect right? When I do this, I get a header saying "Root project" and one line "No configurations" below it. Anyone else having this issue?Nidorf
Hi, I have a similar problem. I'm running gradlew -q dependencies as you suggested bu the only output is ------------------------------------------------------------Root project ------------------------------------------------------------ No configurations am I doing something wrong ?Brasca
./gradlew -q :projectName:dependencies worked for meNaphthyl
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.Conk
in whit console should I run gradle -q dependencies and where is it?Gloom
@xedo: "in whit console should I run gradle -q dependencies" -- I used a terminal window in Ubuntu. The answer will vary by your desktop OS. "and where is it?" -- I installed a local copy of Gradle from gradle.org.Cluck
@Cluck I did it (Windows) but doesn't recognizes 'gradle'Gloom
@xedo: Make sure it is in your PATH. You will fine the Gradle executable in the bin/ directory of wherever you installed Gradle.Cluck
If you get 'No configurations' then you need to do './gradlew -q :app:dependencies'. This is confusing since everyone is saying to use ':projectName:dependencies', However, it's the application directory, not the project name that needs to go there!Ewell
For eclipse here's the SO answer: #23058878Pipit
@Cluck Could you please assist me in finding out the duplicate dependency in this question? I've tried almost every option but to no avail.Noonan
B
123

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

android {
    dexOptions {
        preDexLibraries = false
    }
}
Bolingbroke answered 3/6, 2014 at 21:32 Comment(7)
Worked for me! Is there any down sides of doing it this way?Perspicacity
@BarrieGalitzky I haven't ran into any issues so farBolingbroke
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!Alyce
dexOptions not found.Veronaveronese
This is the best and easiest solution to the problem. Thx man!Macerate
Not worked for me!! After adding the module inside android package i got the same error which appeared previously...Internationalize
After adding this, I got "Translation has been interrupted" error. Guess I've to give CommonsWare method a try.Noonan
E
36

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.

Executrix answered 18/1, 2016 at 9:36 Comment(0)
I
33

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

Invoice answered 30/4, 2014 at 15:20 Comment(5)
More specific instruction? Can't find "androidDependencies". ThxHarar
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.Veroniqueverras
Where is the Gradle view?Upland
@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 taskPropolis
thank you man, i posted screenshots explaining your answer to make it easier.Executrix
A
11

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'
Albertinaalbertine answered 22/2, 2017 at 1:27 Comment(2)
keep the support version to be same is simple solution and exclude module is not work for me.Matsuyama
I solved with the second solution as well! Same conflict but with Butter Knife version 8.8.1 Example: implementation ('com.jakewharton:butterknife:8.8.1') { exclude module: 'support-compat' } annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'Weaken
S
9

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

Senile answered 18/5, 2015 at 7:36 Comment(1)
Thanks, was missing double parenthesis!Gnash
M
8
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.

Milt answered 9/7, 2015 at 6:18 Comment(0)
S
8

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

Succinctorium answered 15/11, 2015 at 14:22 Comment(1)
Multidexing can make your app start up speed slower, only use it if you really have to.Loudish
L
6

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.

Lightship answered 26/3, 2014 at 16:35 Comment(1)
Had the same error after upgrading intellij, cleaning the project fixed the issue.Twinflower
A
5

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

Amine answered 28/7, 2015 at 10:36 Comment(0)
K
3

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

}

Kelwin answered 14/12, 2015 at 14:38 Comment(0)
A
3

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

Arleenarlen answered 20/11, 2016 at 12:48 Comment(0)
S
3

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.

Stimulate answered 17/3, 2017 at 7:25 Comment(0)
A
2

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.

Azo answered 26/1, 2015 at 3:50 Comment(0)
C
2

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

Challah answered 18/9, 2015 at 16:28 Comment(0)
R
2

Deleting all files from Gradle cache fixed my problem.

on Linux:

rm -rf ~/.gradle/caches/*
Reversioner answered 9/7, 2016 at 17:35 Comment(0)
R
2

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

Reveal answered 24/9, 2016 at 18:19 Comment(0)
M
1

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

Metzger answered 18/8, 2015 at 3:29 Comment(1)
this should be a comment or else you should explain it in a better way.Avoirdupois
B
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

Breaker answered 22/6, 2019 at 12:44 Comment(0)
C
0

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:+'
Circumlunar answered 16/3, 2017 at 18:13 Comment(0)
S
0

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

Secluded answered 4/6, 2017 at 14:3 Comment(0)
Y
0

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.

Yusuk answered 16/8, 2017 at 4:5 Comment(0)
H
0

I had the same problem, and my solution is changing the support version '27.+'(27.1.0) to '27.0.1'

Hyperthermia answered 28/2, 2018 at 8:16 Comment(0)
U
0

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

Unpeg answered 14/3, 2018 at 11:23 Comment(0)
D
0

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

cordova.system.library.7=com.android.support:appcompat-v7:27.1.0
Debouchment answered 25/3, 2018 at 18:20 Comment(0)
A
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

Ale answered 22/8, 2018 at 20:28 Comment(1)
Hi Welcome to Stack Overflow. But please do not repeat answers, apart from already having 24 answers, building clean was already provided as an answer by ashishduh. Thanks!Tachygraphy

© 2022 - 2024 — McMap. All rights reserved.