我正在尝试使用Google地图构建应用,但每当我尝试运行它时,都会出现错误消息。我已将以下代码添加到build.gradle:
dependencies {
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
以下是错误消息:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Fredrik\AppData\Local\Android\android-studio\sdk\build-tools\19.0.3\dx.bat --dex --output
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\dex\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\classes\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\dependency-cache\debug
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\android-support-v4-0245b39e700edf6a0cb399c720bb8d324f78e6d1.jar
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\classes-05dd9eee723585a17563ec87ce727a6f7bafa3c6.jar
C:\Users\Fredrik\AndroidStudioProjects\Skollunch\app\build\pre-dexed\debug\support-v4-19.0.1-b477505a5fac609297d4a580b1fdd1110916d42b.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
当我删除build.gradle中的代码时,它运行正常,但是地图当然不会起作用;)。这不仅仅是Play服务的情况,但是当我尝试添加支持库时它会做同样的事情。
有谁知道可以帮我解决问题的东西?
答案 0 :(得分:0)
使用Gradle时,不要直接包含jar文件来包含android-support-v4;如果你这样做,构建系统不能消除它可能通过直接或传递依赖性遇到的支持库的多个副本,并且你得到了这个错误。相反,从 libs 目录中删除jar并通过在构建文件的dependencies
块中提供其Maven坐标来包含它:
dependencies {
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.android.support:support-v4:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}