Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - error: package android.support.test does not exist

I try to run unit test, but I get error

error: package android.support.test does not exist

In my grade file I have

testImplementation 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'

But I still get error

Gradle

import java.util.regex.Pattern


apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply from: 'versionCode.gradle'


android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionName "1.0." + VERSION_CODE
        versionCode Integer.parseInt(VERSION_CODE)
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            res.srcDirs =
                    [...]
            java.srcDirs = ['src/main/java', 'src/main/java/UserStories']
        }
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://jitpack.io" }

    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'jniLibs', include: ['*.jar', '.so'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.squareup.retrofit2:converter-scalars:2.3.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'co.lujun:androidtagview:1.1.4'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'jp.wasabeef:glide-transformations:3.0.1'
    compile "com.daimajia.swipelayout:library:1.2.0@aar"
    implementation 'com.tapadoo.android:alerter:2.0.6'

    compile group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

    testImplementation "org.mockito:mockito-core:2.+"
    testImplementation 'junit:junit:4.12'

    compile fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation "org.robolectric:robolectric:3.8"
    compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true;
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }

    implementation 'com.google.dagger:dagger-android:2.11'
    implementation 'com.google.dagger:dagger-android-support:2.11'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
}


tasks.whenTaskAdded { task ->
    if (task.name == 'generateReleaseBuildConfig') {
        task.dependsOn 'increaseVersionCode'
    }
}
like image 629
Alexey K Avatar asked Sep 03 '25 04:09

Alexey K


2 Answers

Make sure your gradle file is like this:

android {
    ...
    defaultConfig {
        ...
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ...
    }
    ...
}
dependencies {
    ...
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
    ...
}

Does it work now?

like image 103
Jacob Celestine Avatar answered Sep 04 '25 20:09

Jacob Celestine


In the gradle file for example two, replacing androidTestImplementation with implementation it seems to fix the issue. Check and update me once.

like image 20
arjun ds Avatar answered Sep 04 '25 19:09

arjun ds