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;
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.+'
}
I am using Android Studio, but the tests are run from command line.
Running non-emulator based tests with roboelectric (gradlew test
) works fine.
I believe it is a jar file that is included twice, but don't know which one and how to fix. Suggestions?
EDIT
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?