运行测试用例文件时发生依赖性错误

时间:2019-04-29 05:37:55

标签: android

我收到此错误:

  

找不到满足版本限制的'androidx.test:rules'版本:      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test.espresso:espresso-intents:3.1.0-alpha4'->'androidx.test:rules:1.1.0-alpha4'      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'com.github.jwir3.RESTMock:android:0.1.4alpha'->'androidx.test:rules:1.1.0-alpha3'      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3      依赖路径'Deliver:app:unspecified'->'androidx.test:rules:1.1.0'      约束路径'Deliver:app:unspecified'->'androidx.test:rules:{严格为1.1.0-alpha3}',原因如下:debugRuntimeClasspath使用版本1.1.0-alpha3

3 个答案:

答案 0 :(得分:1)

您需要为AndroidJUnitRunner和JUnit规则添加最新的依赖项,即

androidTestImplementation'androidx.test:rules:1.1.0'

还要确保添加核心库进行测试。如果需要,也可以导入断言和特浓咖啡库。看看这个官方的Android文档

https://developer.android.com/training/testing/set-up-project

答案 1 :(得分:0)

apply plugin: 'com.android.application'


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.delivery"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunner 'io.appflate.restmock.android.RESTMockTestRunner'
        multiDexEnabled true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }

    configurations.all {
        exclude module: 'okhttp-ws'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    //gson
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
    implementation 'com.google.android.material:material:1.0.0-rc01'

    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    //butter knife
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'

    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
    //glide
    implementation 'com.github.bumptech.glide:glide:4.8.0'

    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    testImplementation 'junit:junit:4.12'
    testImplementation "org.robolectric:robolectric:3.4.2"
    testImplementation 'org.hamcrest:hamcrest-library:1.3'
    testImplementation "org.mockito:mockito-core:2.11.0"

    androidTestImplementation 'org.mockito:mockito-android:2.11.0'
    androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'

    implementation 'com.github.jwir3.RESTMock:android:0.1.4alpha'

    testImplementation 'com.jraska.livedata:testing:1.1.0'
    testImplementation 'androidx.arch.core:core-testing:2.1.0-alpha02'

    androidTestImplementation 'androidx.test:core:1.0.0'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.0.0'
    androidTestImplementation 'androidx.test.ext:truth:1.0.0'
    androidTestImplementation 'com.google.truth:truth:0.42'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
    androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'

}
repositories {
    mavenCentral()
    maven {
        url 'https://maven.google.com'
    }
}

答案 2 :(得分:0)

根据您的错误消息,我认为您遇到了 com.github.jwir3.RESTMock 库的问题,因为它们使用的是不同版本的测试标尺和运行程序。 您可以绕过这种定义排除的方式(使用您需要的排除,我需要两者都使用):

implementation("com.github.jwir3.RESTMock:android:$restMockVersion") {
    exclude group: 'androidx.test', module: 'runner'
    exclude group: 'androidx.test', module: 'rules'
}

希望有帮助