仪器测试:找不到依赖项

时间:2019-03-22 10:12:15

标签: android kotlin android-gradle android-testing instrumented-test

我正在尝试对我的项目启动一个简单的仪器化测试,但是出了点问题。这是我的简单测试类(默认类):

@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getTargetContext()
        assertEquals("com.mypackage.a123myappkotlin", appContext.packageName)
    }
}

但是当我尝试启动它时,出现此错误:

Cannot find a version of 'com.squareup.okhttp3:okhttp' that satisfies the version constraints: 
Dependency path '123myappkotlin:app:unspecified' --> 'com.squareup.okhttp3:logging-interceptor:3.12.0' --> 'com.squareup.okhttp3:okhttp:3.12.0'
Dependency path '123myappkotlin:app:unspecified' --> 'com.squareup.okhttp3:mockwebserver:3.14.0' --> 'com.squareup.okhttp3:okhttp:3.14.0'
Dependency path '123myappkotlin:app:unspecified' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
Dependency path '123myappkotlin:app:unspecified' --> 'com.squareup.retrofit2:converter-gson:2.4.0' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
Constraint path '123myappkotlin:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.12.0' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path '123myappkotlin:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.12.0' because of the following reason: debugRuntimeClasspath uses version 3.12.0

这是我在此错误上出现的依赖关系的相对应用

implementation "com.squareup.okhttp3:logging-interceptor:$logger_interception_version"
androidTestImplementation "com.squareup.okhttp3:logging-interceptor:$logger_interception_version"
testImplementation "com.squareup.okhttp3:logging-interceptor:$logger_interception_version"

androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.14.0'

implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

其中的版本值为:

ext.logger_interception_version = '3.12.0'
ext.retrofit_version = '2.4.0'

怎么了?

0 个答案:

没有答案