Android的测试:“多DEX文件”使用'支票的gradle connectedCheck“时 [英] Android testing: 'Multiple dex files' when using 'gradle check connectedCheck'
问题描述
当我运行Android基于仿真的测试,
When I run android emulator-based tests with:
gradlew check connectedCheck
...它失败:
... it fails with:
com.android.dx.util.DexException: Multiple dex files define Lorg/hamcrest/Description;
下面是我的build.gradle文件:
Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}
apply plugin: 'android'
apply plugin: 'android-test'
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
gradleVersion = '1.9'
}
android {
compileSdkVersion 17
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 13
targetSdkVersion 18
}
sourceSets {
instrumentTest.setRoot('src/test')
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile fileTree(dir: 'libs', include: '*.jar')
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}
我使用Android的工作室,但测试都是在命令行中运行。
I am using Android Studio, but the tests are run from command line.
运行带有roboelectric非基于模拟器测试( gradlew测试
)的罚款。
Running non-emulator based tests with roboelectric (gradlew test
) works fine.
我相信这是包括两次jar文件,但不知道哪一个,以及如何解决。
建议?
I believe it is a jar file that is included twice, but don't know which one and how to fix. Suggestions?
修改
这似乎是在 instrumentTestCompile'的JUnit:JUnit的:4.10
行导致该问题。但是,当我取了这一点,该roboelectric测试不编译。我应该如何配置,这样我可以同时运行仿真器和基于roboeletric为基础的测试?
It seems that it is the instrumentTestCompile 'junit:junit:4.10'
line that is causing the problem. But when I take that out, the roboelectric test doesn't compile. How should I configure this so that I can run both emulator-based and roboeletric-based tests?
推荐答案
这是因为JUnit的4.10包括一些Hamcrest类(淘气)。它的固定在4.11因此只需升级。
This is because JUnit 4.10 includes some Hamcrest classes (naughty). It's fixed in 4.11 so just upgrade.
这篇关于Android的测试:“多DEX文件”使用'支票的gradle connectedCheck“时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!