Gradle在添加Google Play服务后无法构建
gradle Dependencies我已经尝试过将play-services-wearable条目放在一起而第二个被排除在外
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')
}
Gradle控制台输出此错误。
* 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
我尝试将此添加到我的build.gradle
dexOptions {
preDexLibraries = false
}
我在Gradle控制台中遇到了同样的错误。我尝试了以下诊断
$ 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
答案 0 :(得分:3)
您使用的是同一个库的不同版本。
在这种情况下,我想你必须删除这一行:
compile files('libs/support-v4-r12.jar')