首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gradle失败:删除kotlintest后无法解决: io

Gradle失败:删除kotlintest后无法解决: io
EN

Stack Overflow用户
提问于 2019-08-02 19:28:33
回答 1查看 379关注 0票数 1

我已经创建了一个新的Android项目,并在Intrument测试和单元测试中设置了mockk:

代码语言:javascript
复制
    androidTestImplementation "io.mockk:mockk:{1.9.3}"
    testImplementation "io.mockk:mockk:{1.9.3}"

Gradle同步正常。

如果我添加kotlintest并再次同步,则一切正常:

代码语言:javascript
复制
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,而把gradle文件留在添加kotlintest之前一样,那么我就会得到错误:

代码语言:javascript
复制
Failed to resolve: io

这是我的最终Gradle文件:

代码语言:javascript
复制
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。

你知道为什么会发生这种事吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-06 10:48:24

您的mockk库版本包含{}

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

代码语言:javascript
复制
testImplementation "io.mockk:mockk:${Version.mockkVersion}"

在您的例子中,当使用固定值时,您不应该使用大括号:

代码语言:javascript
复制
testImplementation "io.mockk:mockk:1.9.3"

它应该可以很好地与此更改同步

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57325617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档