Gradle fails: Failed to resolve: io after removing

2019-08-17 07:34发布

I've created a new Android Project and set up mockk in Intrument test and Unit test:

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

Gradle sync fine.

If I add kotlintest and sync again everything works:

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'
}

But if I remove kotlintest and I leave the gradle file as before adding kotlintest, then I get the error:

Failed to resolve: io

This is my final Gradle file:

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}"
}

I tried cleaning the project and cleaning gradle.

Any idea why this is happening?

Thanks

1条回答
SAY GOODBYE
2楼-- · 2019-08-17 08:17

Your version for the mockk library contains {}.

We usually use them when working with a version that is in a variable or in the ext block:

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

In your case, when working with a fixed value, you shouldn't use the braces:

testImplementation "io.mockk:mockk:1.9.3"

It should sync fine with this change

查看更多
登录 后发表回答