启动connectedDebugAndroidTest gradle任务时出现错误。我对项目执行了同步,它正常完成,但当我启动connectedDebugAndroidTest gradle任务时,该过程失败。
> Could not resolve all task dependencies for configuration ':TestApp:debugAndroidTestRuntimeClasspath'
> Could not resolve org.hamcrest:hamcrest-core:{strictly 1.3}
Required by:
project :TestApp
Cannot find a version of 'org.hamcrest:hamcrest-core' that satisfies the version constraints
Dependency path 'TestApplication:TestApp:unspecified' --> 'androidx.test.ext:junit:1.1.3' --> 'junit:junit:4.12' --> 'org.hamcrest:hamcrest-core:1.3'
Constraint path 'TestApplication:TestApp:unspecified' --> 'org.hamcrest:hamcrest-core:{strictly 1.3}' because of the following reason: debugRuntimeClasspath uses version 1.3
Dependency path 'TestApplication:TestApp:unspecified' --> 'androidx.test.espresso:espresso-contrib:3.4.0' --> 'com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:3.1' --> 'org.hamcrest:hamcrest-core:2.2'
Dependency path 'TestApplication:TestApp:unspecified' --> 'androidx.test.espresso:espresso-core:3.4.0' --> 'org.hamcrest:hamcrest-library:2.2' --> 'org.hamcrest:hamcrest-core:2.2'我的测试依赖项是:
testImplementation "junit:junit:4.13.2"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation "androidx.test:core:1.4.0"
androidTestImplementation "androidx.test:runner:1.4.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.4.0"Android gradle插件的版本为3.4.3,gradle的版本为5.6
附注:因为我花了2天来解决问题,所以添加了“下一代”的问题
发布于 2021-10-28 14:59:29
问题是不同的库需要不同版本的hamcrest。为了解决这个问题,我在我的:TestApp build.gradle文件中编写了以下代码:
configurations.all {
resolutionStrategy {
force "org.hamcrest:hamcrest-core:2.2"
}
}该代码被强制仅使用hamcrest库版本2.2
https://stackoverflow.com/questions/69756393
复制相似问题