java - 无法解析符号 RecyclerViewActions/RecyclerViewMatcher

标签 java android

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

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

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

这是我的导入,也抛出了错误

导入静态 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'
    }

关于java - 无法解析符号 RecyclerViewActions/RecyclerViewMatcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61979399/

相关文章:

android - 是否可以从Android资源xml文件读取gradle变量?

android - 异步任务锁数据库

Java - 如何将旧的代码块空检查方式切换为可选空检查方式?

android - 为什么我的构建在 Android Studio 中失败并出现异常 "Failed to find byte code for android/support/v7/app/ActionBarActivity"?

android - 如何通过 Android NDK 编译 C++ 项目

java - 从 unwrapped() 获得的 java ArrayList 转换为 Scala 列表

android - 两种方法更新 Android App Widget 有什么区别?

java - 在 OOP 中使用太多单例和静态方法会有什么风险?

java - 如何使用 JedisConnectionFactory 访问多个远程 redis?

java - maven 没有为 spring boot 项目创建 META-INF