【问题标题】:dependency error while running test case file运行测试用例文件时出现依赖错误
【发布时间】:2019-04-29 05:37:54
【问题描述】:

我收到此错误:

找不到满足版本约束的“androidx.test:rules”版本: 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 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:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 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:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3 依赖路径 'Deliver:app:unspecified' --> 'androidx.test:rules:1.1.0' 约束路径 'Deliver:app:unspecified' --> 'androidx.test:rules:{strictly 1.1.0-alpha3}' 因为以下原因:debugRuntimeClasspath 使用版本 1.1.0-alpha3

【问题讨论】:

    标签: android


    【解决方案1】:

    你需要为AndroidJUnitRunner和JUnit Rules添加最新的依赖,即

    androidTestImplementation 'androidx.test:rules:1.1.0'

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

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

    【讨论】:

      【解决方案2】:

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

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

      希望对你有帮助

      【讨论】:

        【解决方案3】:
        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'
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2015-07-08
          • 2012-07-31
          • 2013-07-08
          • 2020-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-03
          相关资源
          最近更新 更多