如何解决 Cannot find a version of 'com.google.android.material:material' that satisfy the version constraints

how to solve Cannot find a version of 'com.google.android.material:material' that satisfies the version constraints

我正在从事浓缩咖啡测试,我需要以下依赖项:

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'

为了 recycler-view 完成测试,但是当我添加这个依赖时我得到了这个错误:

Caused by: org.gradle.api.GradleException: Cannot find a version of >'com.google.android.material:material' that satisfies the version >constraints: Dependency path 'myproject:app:unspecified' --> >'com.google.android.material:material:1.0.0-beta01' Constraint path 'myproject:app:unspecified' --> >'com.google.android.material:material:{strictly 1.0.0-beta01}' because >of the following reason: debugRuntimeClasspath uses version 1.0.0->beta01

我可以理解这个错误是因为以下依赖关系:

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

我可以通过将 material 依赖项更改为其他版本来解决它,但是如果我更改 material 依赖项,设计就会错过问题,我不想更改它

我已经尝试使用较低版本的 esspreso-contrib 来解决它,但仍然出现此错误

我真的不想改变 material 依赖,我需要测试,所以请知道的人解决它,感激不尽

提前致谢

[edit] 抱歉没有提到该应用 运行 没有错误但只有当我 运行 测试时才会出现此错误

恐怕我无法在测试项目中重现您的错误。

但是我的第一个想法是 transative dependency 问题,因为我怀疑 espresso-contrib 正在提取和共享 material (1.0.0) 的过时版本。

这可能是一些 android x 测试实用程序库共享的 issue

尝试替换:

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'

与:

androidTestImplementation ('androidx.test.espresso:espresso-contrib:3.2.0') {
    exclude group: 'com.google.android.material', module: 'material'
}