4

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?

Roar Skullestad
  • 2,427
  • 3
  • 26
  • 35
  • do you have support library jar file in your libs directory? I got this issue when I include for build path jar file and also libs directory (where support library was) as dependencies (in eclipse). I did it at random and eclipse thought that support library is there twice. – Marek Dovina Jan 10 '14 at 11:03
  • same problem over here – Extranion Apr 23 '14 at 11:51

1 Answers1

2

This is because JUnit 4.10 includes some Hamcrest classes (naughty). It's fixed in 4.11 so just upgrade.

artbristol
  • 32,010
  • 5
  • 70
  • 103