Gradle failed to build with error Multiple dex files define

倖福魔咒の 提交于 2019-12-11 03:13:23

问题


Gradle failed to build after I added google play services

gradle Dependencies I've tried both with play-services-wearable entries together and the second one excluded

dependencies {
    compile 'com.google.android.gms:play-services-wearable:6.5.+'
    compile 'com.android.support:support-v13:21.0.+'
    wearApp project(':wear')
    compile 'com.google.android.gms:play-services-wearable:6.5.87'
    compile files('libs/crashlytics.jar')
    compile files('libs/cup-v1.0.0.jar')
    compile files('libs/support-v4-r12.jar')
    compile files('libs/gson-2.2.4.jar')
}

The Gradle console output this error.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Users/jshultz/android-sdks/build-tools/21.1.2/dx --dex --no-optimize --output /Users/jshultz/Documents/workspace/MayDay/app/build/intermediates/dex/debug --input-list=/Users/jshultz/Documents/workspace/MayDay/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)



* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 3.524 secs

I tried adding this to my build.gradle

dexOptions {
    preDexLibraries = false
}

I got the same error in the Gradle Console. I tried the following diagnostic

$ gradle -q dependencies

------------------------------------------------------------
Project :app
------------------------------------------------------------

_debugApk - ## Internal use, do not manually configure ##
+--- com.google.android.gms:play-services-wearable:6.5.+ -> 6.5.87
|    \--- com.google.android.gms:play-services-base:6.5.87
|         \--- com.android.support:support-v4:21.0.0 -> 21.0.3
|              \--- com.android.support:support-annotations:21.0.3
+--- com.android.support:support-v13:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 (*)
\--- com.google.android.gms:play-services-wearable:6.5.87 (*)

_debugCompile - ## Internal use, do not manually configure ##
+--- com.google.android.gms:play-services-wearable:6.5.+ -> 6.5.87
|    \--- com.google.android.gms:play-services-base:6.5.87
|         \--- com.android.support:support-v4:21.0.0 -> 21.0.3
|              \--- com.android.support:support-annotations:21.0.3
+--- com.android.support:support-v13:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 (*)
\--- com.google.android.gms:play-services-wearable:6.5.87 (*)

_debugTestApk - ## Internal use, do not manually configure ##
No dependencies

_debugTestCompile - ## Internal use, do not manually configure ##
No dependencies

_releaseApk - ## Internal use, do not manually configure ##
+--- com.google.android.gms:play-services-wearable:6.5.+ -> 6.5.87
|    \--- com.google.android.gms:play-services-base:6.5.87
|         \--- com.android.support:support-v4:21.0.0 -> 21.0.3
|              \--- com.android.support:support-annotations:21.0.3
+--- com.android.support:support-v13:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 (*)
\--- com.google.android.gms:play-services-wearable:6.5.87 (*)

_releaseCompile - ## Internal use, do not manually configure ##
+--- com.google.android.gms:play-services-wearable:6.5.+ -> 6.5.87
|    \--- com.google.android.gms:play-services-base:6.5.87
|         \--- com.android.support:support-v4:21.0.0 -> 21.0.3
|              \--- com.android.support:support-annotations:21.0.3
+--- com.android.support:support-v13:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 (*)
\--- com.google.android.gms:play-services-wearable:6.5.87 (*)

androidJacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.7.1.201405082137

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.1.201405082137
     +--- org.jacoco:org.jacoco.core:0.7.1.201405082137
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     +--- org.jacoco:org.jacoco.report:0.7.1.201405082137
     |    +--- org.jacoco:org.jacoco.core:0.7.1.201405082137 (*)
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     \--- org.jacoco:org.jacoco.agent:0.7.1.201405082137

androidTestApk - Classpath packaged with the compiled 'androidTest' classes.
No dependencies

androidTestCompile - Classpath for compiling the androidTest sources.
No dependencies

androidTestProvided - Classpath for only compiling the androidTest sources.
No dependencies

androidTestWearApp - Link to a wear app to embed for object 'androidTest'.
No dependencies

apk - Classpath packaged with the compiled 'main' classes.
No dependencies

archives - Configuration for archive artifacts.
No dependencies

compile - Classpath for compiling the main sources.
+--- com.google.android.gms:play-services-wearable:6.5.+ -> 6.5.87
|    \--- com.google.android.gms:play-services-base:6.5.87
|         \--- com.android.support:support-v4:21.0.0 -> 21.0.3
|              \--- com.android.support:support-annotations:21.0.3
+--- com.android.support:support-v13:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 (*)
\--- com.google.android.gms:play-services-wearable:6.5.87 (*)

debugApk - Classpath packaged with the compiled 'debug' classes.
No dependencies

debugCompile - Classpath for compiling the debug sources.
No dependencies

debugProvided - Classpath for only compiling the debug sources.
No dependencies

debugWearApp - Link to a wear app to embed for object 'debug'.
No dependencies

default - Configuration for default artifacts.
No dependencies

provided - Classpath for only compiling the main sources.
No dependencies

releaseApk - Classpath packaged with the compiled 'release' classes.
No dependencies

releaseCompile - Classpath for compiling the release sources.
No dependencies

releaseProvided - Classpath for only compiling the release sources.
No dependencies

releaseWearApp - Link to a wear app to embed for object 'release'.
No dependencies

wearApp - Link to a wear app to embed for object 'main'.
\--- project :wear

回答1:


You are using different versions of the same library.

In this case I suppose you have to remove this line:

compile files('libs/support-v4-r12.jar')


来源:https://stackoverflow.com/questions/28509538/gradle-failed-to-build-with-error-multiple-dex-files-define

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!