android - Gradle失败:无法解决:删除kotlintest之后的io

标签 android gradle mockk kotlintest

我创建了一个新的Android项目,并在Intrument测试和Unit测试中设置了ockk:

    androidTestImplementation "io.mockk:mockk:{1.9.3}"
    testImplementation "io.mockk:mockk:{1.9.3}"

Gradle 同步良好。

如果我添加kotlintest并再次同步,则一切正常:
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.testing"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //Mocking framework
    androidTestImplementation "io.mockk:mockk:{1.9.3}"
    testImplementation "io.mockk:mockk:{1.9.3}"

    //Testing framework
    androidTestImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
    testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
}


但是,如果我删除kotlintest并像添加kotlintest之前一样保留gradle文件,则会收到错误消息:
Failed to resolve: io

这是我最后的Gradle文件:
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.testing"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //Mocking framework
    androidTestImplementation "io.mockk:mockk:{1.9.3}"
    testImplementation "io.mockk:mockk:{1.9.3}"
}

我尝试清理项目并清理gradle。

知道为什么会这样吗?

谢谢

最佳答案

您的mockk库版本包含{}

我们通常在处理变量或ext块中的版本时使用它们:

testImplementation "io.mockk:mockk:${Version.mockkVersion}"

对于您的情况,使用固定值时,不应使用花括号:
testImplementation "io.mockk:mockk:1.9.3"

它应该与此更改保持同步

关于android - Gradle失败:无法解决:删除kotlintest之后的io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57325617/

相关文章:

java - dexifying 18.5 MB "android-4.1.1_r1.jar"给出 "java.lang.OutOfMemoryError: Java heap space"

java - delphi xe5安装包

android - 当应用程序从低内存中返回时系统重新创建 fragment

unit-testing - Kotlin & MockK - 如果从另一个方法调用模拟方法,则模拟不起作用

android - 如何检查一个方法是否没有被 mockk 调用?

android - Kotlin Mockk 错误 : Missing calls inside verify { . .. } block

java - 传递参数与函数内部分配,java/android 中的内存泄漏?

java - 无法将 Simple Spring MVC 项目部署到 AWS Tomcat 8

android - 添加Android支持库时Gradle中的错误

Android - Gradle 错误