Android:测试运行失败:由于'java.lang.IncompatibleClassChangeError'导致仪表运行失败

pbe*_*lov 9 android automated-tests unit-testing gradle

我有一些项目有几个单元测试.当我尝试在Android Studio或终端上执行测试时出现gradle clean connectedCheck以下错误:Test running failed: Instrumentation run failed due to 'java.lang.IncompatibleClassChangeError' 它在Android 5.x设备上重现,但在4.x上没有错误发生.但是如果我尝试在Android Studio中运行单独的测试包,套件,类或某些测试,测试进展顺利.

我不明白为什么.我需要从终端执行测试

build.gradle文件:

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')
}
Run Code Online (Sandbox Code Playgroud)

有人有什么建议吗?

小智 1

这取决于您包含哪些库。就我而言,当我包含 espresso.contrib 库时遇到了这个问题。

不过你可以尝试做这样的事情。/sf/answers/2059641951/