Android instrumented unit testing Cannot resolve symbol 'AndroidJUnit4'

不打扰是莪最后的温柔 提交于 2019-12-12 11:48:51

问题


I trying to add Android Support Instrumentation test to my application, but i run this problem: Cannot resolve symbol 'AndroidJUnit4'

Its seems i don't have the package android.support.test.runner

my app's build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "---PACKAGENAME---"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile file("../keys/debug.jks")
            storePassword "*"
            keyAlias "debug"
            keyPassword "*"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug_uat {
            debuggable true
            signingConfig signingConfigs.debug
        }
        debug_int {
            debuggable true
            signingConfig signingConfigs.debug
        }
        staging {
            debuggable false
            signingConfig signingConfigs.debug
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile project(path: ':volley')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'

    androidTestCompile 'com.android.support:support-annotations:23.4.0'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
}

The gradle sync and the build is ok, but i can not add the support AndroidJUnitRunner to my run config and my android test class (the class is in androidTest filder)

Please help! Apoth

UPDATE

I found the problem. I using various build types, and i just needed to add testBuildType "debug_uat" to my build.gradle.

来源:https://stackoverflow.com/questions/37695260/android-instrumented-unit-testing-cannot-resolve-symbol-androidjunit4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!