我正在尝试在我的Android应用程序中为回收站视图编写测试。我收到“ RecyclerViewActions”和“ RecyclerViewMatcher”的无法解析符号错误。

这是我的测试中的辅助方法,其中抛出“无法解析符号”错误。

````// Convenience helper
public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) {
    return new RecyclerViewMatcher(recyclerViewId);
}````


这是我的导入,其中也引发了错误

import static androidx.test.espresso.contrib.RecyclerViewActions;

这是我的应用程序级别build.gradle依赖项:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:rules:1.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation('androidx.test.espresso:espresso-contrib:3.2.0') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
    }
}````

最佳答案

添加应用程序级别build.gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.google.android.material:material:1.0.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'

    //Testing
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-contrib:3.0.2'){
        exclude group: 'com.android.support', module: 'appcompat'
        exclude module: 'recyclerview-v7'
        exclude module: 'appcompat-v7'
    }```

09-27 14:16