1

I'm writing a test suite with mockwebserver. I entered all of the dependencies from the official github page. Every time I try to run the test I receive Unresolved reference: mockwebserver

There's no option to import. The lettering isn't red on the import. Android Studio doesn't prompt anything. There are no other errors aside from ones related to the unresolved reference.

Screenshot: enter image description here


build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id("org.jetbrains.kotlin.android.extensions")
}

android {
    compileSdk 31

    useLibrary("android.test.runner")
    useLibrary("android.test.base")
    useLibrary("android.test.mock")

    defaultConfig {
        applicationId "com.example.moviespotter"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures {
        viewBinding = true
        compose true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.5.21'
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
    testImplementation 'junit:junit:4.13'
    testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'com.squareup.retrofit2:retrofit:2.7.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
    implementation 'com.squareup.okhttp3:okhttp:4.3.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.github.bumptech.glide:glide:4.10.0' //Glide
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "io.coil-kt:coil-compose:1.3.1"
    annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
    androidTestImplementation 'com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'
}

2 Answers 2

5

Since this is in androidTest, it should be

androidTestImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

Also mixing 5.0.0-alpha.2 and 4.3.1 is a world of hurt.

Sign up to request clarification or add additional context in comments.

2 Comments

Which versions would you recommend? I was trying out different combos until I found one that worked.
Just use 4.9.2 for everything, it's the most recent stable release.
-1

I found the culprit.

When adding the dependency to the build.gradle file it should read implementation.

Change From: testImplementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

To: implementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

1 Comment

implementation is too high, it's accidentally fixing it by making it a dependency of src/main, while you want it to be included just for tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.