尽管 testImplementation 中存在 Mockito 依赖项,但 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())
}
最佳答案
终于!我已经在一天结束时解决了它。我将列出我执行的步骤。
检查了module.iml 文件中的
test source directores
和classpath
,一切正常<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
已检查
本地 gradle 缓存
中可用的版本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 版本工作。
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 ;)
关于Android Studio 无法解析 Mockito 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432673/