我有一个在Android Studio 0.8.1和Gradle上运行的项目,没有任何问题,但如果我尝试在我的项目中运行一些测试,我会得到以下错误:
Error:Execution failed for task ':app:dexDebugTest'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Leonardo\AppData\Local\Android\android-studio\sdk\build-tools\android-4.4W\dx.bat --dex --num-threads=4 --output C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\dex\test\debug C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\classes\test\debug C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\dependency-cache\test\debug C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\ant-1.8.0-90f6540aeb424fece79cbcf5a9c142d1639370bb.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\ant-launcher-1.8.0-75752524e2cfe22e800164221abdcac48de27e2a.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\asm-5.0.1-c8cc57fa69d410715b92ec859560fc814d01d95e.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\asm-analysis-5.0.1-5442ee256c0f3632ab4b32a9a5fce82929bf4069.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\asm-commons-5.0.1-588ac8e1b7216878c1af3260f5fcdf5d99cff8ab.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\asm-tree-5.0.1-553326de7527bdbeb7b59518b73b9137e3d8d2f2.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\asm-util-5.0.1-ef2fad64c577c021e5a15f4437224e32e26eff9f.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\backport-util-concurrent-3.1-c889acaff21236987cfa34814d3d0b09322c08c6.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\classworlds-1.1-alpha-2-eb45cc5ebd3a72fe080272e80fe74214a835c2c6.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\commons-codec-1.3-383c4836f0e583f6ca4687555474bce80fb4b8c3.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\fest-android-1.0.8-4accc48dc10f44e67648da9dc2ddcd9df6c55670.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\fest-assert-core-2.0M10-afffd97c0da2a18452675e26a71819f699a2315c.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\fest-reflect-1.4.1-eccad0370faa987892a231eea79a7c5832d4ae20.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\fest-util-1.2.5-918956ab9a2c5b7bbed411cd7e866c4eb9228ce3.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\hamcrest-core-1.3-a89084788a49a921a7573b5efa8ff29f99a11459.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\junit-4.11-8cb426b6ecb53ec20b0fd767afeff8c7c31fe904.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-ant-tasks-2.1.3-b289572b8b55f16a8213e9081b7a4ccf1e92897c.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-artifact-2.2.1-431ffca03ac082aa829dd81bee45bfd754938ed4.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-artifact-manager-2.2.1-26381e227ec6a84aadc833b5c8423cec957e7b21.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-error-diagnostics-2.2.1-eda257a68ef2aa2b97b5d6e7fa29cb2b6cf778bc.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-model-2.2.1-c09ac5e8d9c4980f10a653344c24daec764957dd.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-plugin-registry-2.2.1-f9ee3e8636fcd92ab0e1cb3c0df032e07b4c903c.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-profile-2.2.1-3b1a36de8b8cf219b16f24c849c640b1fea16957.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-project-2.2.1-025981ae0201c9218005a49f76f8db2665d4c6c3.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-repository-metadata-2.2.1-fc67127094027c65ff3efabc7e1ff0e0d59027e8.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\maven-settings-2.2.1-651f9aa0ee6954e89848478f6fa6dfddc415606e.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\nekohtml-1.9.6.2-2d990a336f175c6d5760c4daff597f1a99d786ed.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\objenesis-1.3-aab47089b8da4c8da409dbaa4b6f43f2e7ff30fe.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\plexus-container-default-1.0-alpha-9-stable-1-3718ce6697ffbab29c91a5005c51b90bd917ee89.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\plexus-interpolation-1.11-ba3a36ccb9ddc80b02f887e8b5622467a601500a.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\plexus-utils-1.5.15-5f0d70d8950e358a32f6416566aa6438053ee765.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\robolectric-2.3-18ca41a9e98eb103e8c01cba2475df1e45375079.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\sqlite4java-0.282-30dcf2ef4dc673dfed67e316239ce0eaf092252e.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\support-v4-19.1.0-7f265a1ac05f41075f3ac1607c1e7f354051ec1a.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\vtd-xml-2.11-22208f24be860db5223884581f94dd21b5abfcf4.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\wagon-file-1.0-beta-6-ae669046a35b6d27a65c553a273b2259399ea893.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\wagon-http-lightweight-1.0-beta-6-74abcd81bf7e536d42eefda098b0aab377f67f99.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\wagon-http-shared-1.0-beta-6-cd7b2e8f527a7b0f8892019e03b4423fd2aaf4c7.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\wagon-provider-api-1.0-beta-6-68a307c3b5f4b360aec40e10498ce9deb274f9bf.jar C:\Users\Leonardo\AndroidstudioProjects\mymoney\app\build\intermediates\pre-dexed\test\debug\xercesMinimal-1.9.6.2-1c278ddb859c5724499c536c95ce4228b229abc1.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/codehaus/classworlds/BytesURLConnection;
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 文件如下:
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}
apply plugin: 'android'
apply plugin: 'robolectric'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.maddogs.mymoney"
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest.setRoot('src/test') //note that this is androidTest instead of instrumentTest
}
}
dependencies {
compile files('libs/crashlytics.jar')
//compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile('de.keyboardsurfer.android.widget:crouton:1.8.4@aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
androidTestCompile 'junit:junit:4.11'
androidTestCompile 'org.robolectric:robolectric:2.3+'
androidTestCompile 'com.squareup:fest-android:1.0.+'
compile 'com.android.support:appcompat-v7:20.+'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup:otto:1.3.4'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.google.android.gms:play-services:3.1.+'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.android.support:support-v4:19.+'
}
有什么想法吗?如果你们需要更多代码,请告诉我!谢谢