9

I have some projects with several unit tests. When I try to execute tests in Android Studio or from terminal using gradle clean connectedCheck I got the following error: Test running failed: Instrumentation run failed due to 'java.lang.IncompatibleClassChangeError' It is reproduced on Android 5.x devices, but on 4.x no errors happen. But if I try to run separate tests package, suite, class or certain test in Android Studio, tests are going well.

I don't understand why. I need to execute tests from terminal

build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 18
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.xxx.yyy"
        minSdkVersion 9
        targetSdkVersion 18

        testApplicationId "com.xxx.zzz.tests"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

repositories {
    mavenLocal()

    jcenter()
    mavenCentral()
}

android {
    lintOptions {
        abortOnError false
    }
}

dependencies {
    testCompile 'junit:junit:4.12'

    compile fileTree(dir: 'libs', include: '*.jar')
}

Do anybody have any suggestions?

1 Answer 1

1

It depends on which libs you are including. In my case, I had this problem when I included the espresso.contrib library.

You could try doing something like this though.https://stackoverflow.com/a/29423456/5280584

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.