Android studio 无法解析 Mockito 类

Android studio can not resolve Mockito classes

尽管 Mockito 依赖于 testImplementation,Android Studio 显示红线抱怨,它可以未解决依赖性

下面是 dependencies task 的输出,testImplementation 作为配置。

gradle :exo-audio:dependencies --configuration testImplementation



testImplementation - Implementation only dependencies for 'test' sources. (n)
+--- junit:junit:4.12 (n)
+--- org.hamcrest:hamcrest-all:1.3 (n)
+--- org.mockito:mockito-all:1.10.19 (n)
+--- com.squareup.okhttp3:mockwebserver:4.2.1 (n)
\--- com.google.dagger:dagger:2.24 (n)

(n) - Not resolved (configuration is not meant to be resolved)

这是 Android Studio 显示错误的屏幕截图

I have tried cleaning build cache and invalidate restart, nothing seems to be working. Even I have also tried by removing .idea and .gradle directories manually and loading project again.

I think the problem is with Android Studio, even with studio complaining about the classes, I am able to run tests e.g. for the following test hash code is printed.

@Test
    fun foo() {
        println(repository.hashCode())
    }

终于!我已经在一天结束时解决了它。我会列出我执行的步骤。

  1. 检查了 module.iml 文件中的 test source directoresclasspath,这里一切正常

    <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
    
  2. 选中的版本在 local gradle cache

    中可用
    allaudin@geek ~/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core$ ls
    
    1.10.19  2.10.0  2.19.0  2.27.0  2.28.0  2.28.2  2.6.1  2.7.22
    

最后我尝试了不同的版本,它不适用于版本 直到 2.10.0 然后开始为 版本 2.19.0[=30 工作=].

I tried to figure out the root cause but I have to code a lot before I go to sleep. Over to experts for figuring out why some versions do not work ;)