简体   繁体   中英

Multiple dex files define error in android studio

im a begginer in android studio and im trying to perform a database sync with mysql and a android database. after following a guide (it makes no mention to gradle stuff however so im having to improvise) im left with the bellow error After searching i was told its probably my dependencies but i haven't had much look so far

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/gson-2.2.2.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/android-async-http-1.4.4.jar')
}

my library in the .idea folder look like this

libraries

android_async_http_1_4_4.xml
android_support_v4.xml
appcompat_v7_21_0_3.xml
gson_2_2_2.xml
support_annotations_21_0_3.xml
support_v4_21_0_3.xml

this is the error i got

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Developer Tools/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /Volumes/Untitled/You copy/app/build/intermediates/dex/debug --input-list=/Volumes/Untitled/You copy/app/build/intermediates/tmp/dex/debug/inputList.txt
  Error Code:
    2
  Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)

thank you for any help you can offer me

Gradle knows how to resolve dependency conflicts. You can read about that here : https://gradle.org/docs/current/userguide/dependency_management.html .

So the error is not because appcompat clashes with support-v4 .

It looks like you're referencing twice, libraries from your libs folder.

Either use:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/gson-2.2.2.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/android-async-http-1.4.4.jar') }

or:

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile 'com.android.support:appcompat-v7:21.0.3' 
}

However, my recommendation is to also reference support-v4 , gson and android-async as you reference appcompat-v7.

Problem:

With Gradle dependencies, AppCompatv7 also brings in Supportv4 . So, simply remove Supportv4 .jar because you are accidentally adding it twice.

Your dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/gson-2.2.2.jar')
    compile files('libs/android-support-v4.jar') // <-- remove jar
    compile files('libs/android-async-http-1.4.4.jar')
}

Should be:

I also upgraded your .jars into Gradle dependencies.

dependencies {
    compile 'com.android.support:appcompat-v7:22.0.0' // <-- upgraded
    compile 'com.google.code.gson:gson:2.3.1' // <-- upgraded to gradle dependency
    compile 'com.loopj.android:android-async-http:1.4.4' // <-- upgraded to gradle dependency
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM