昨天,当我尝试调试我的应用并在我的设备上运行时,Gradle控制台开始在:mobile:dexDebug
之后立即显示此错误:
AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/parse/ParseFacebookUtils;"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)","position":{},"original":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:106)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:106)"}
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mobile:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_11\bin\java.exe'' finished with non-zero exit value 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
我在这里做了一些研究,它似乎与build.gradle
文件中的依赖关系有关。我的所有SDK都是最新的。
build.gradle(模块:移动):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
defaultConfig {
applicationId "com.intap.tof"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories { mavenCentral() }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
wearApp project(':wear')
compile 'com.parse:parse-android:1.+'
compile fileTree(include: 'achartengine-1.1.0.jar', dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.jjoe64:graphview:4.0.1'
}
答案 0 :(得分:4)
com.android.dex.DexException:多个dex文件定义 LCOM /解析/ ParseFacebookUtils; “ ”位置“:{}, ”原“:” com.android.dex.DexException: 多个dex文件定义Lcom / parse / ParseFacebookUtils;“}
首先在multidex
部分添加build.gradle
。
buildToolsVersion '23.0.1'
设置compile 'com.parse.bolts:bolts-android:1.2.1'
设置compile 'com.parse:parse-android:1.11.0'
更改Gradle构建配置以启用multidex
修改您的应用Gradle构建文件配置以包含支持库并启用multidex输出。
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 23
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
详情请阅读 DexException
https://developer.android.com/intl/es/tools/building/multidex.html
答案 1 :(得分:1)
您收到此异常是因为应用程序已达到 64k方法的限制。因此,您可以在应用程序中启用 multidex ,如其他答案中正确建议的那样。但是,启用multidex会增加您的构建时间,在许多情况下,它不是首选。
因此,我建议您使用不同的proguard文件进行调试和发布版本(在调试版中不要混淆变量和类名)。在大多数情况下, Proguard 将有助于克服此异常。如果这不起作用,那么你必须使用multidex。
答案 2 :(得分:0)
我解决了这个问题!
我切换回Parse SDK 1.9.3,然后它突然起作用了!
无论如何,谢谢你们帮我解决这个问题。非常高兴。