更新库后仪器测试失败
Instrumentation test fails after updating libraries
我的所有仪器测试都有这些 gradle 依赖项:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
implementation 'androidx.fragment:fragment:1.1.0-alpha01'
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
一旦我将它们更新为:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
implementation 'androidx.fragment:fragment:1.2.0-alpha01'
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
和运行测试,我得到以下错误:
Cannot find a version of 'androidx.test:core' that satisfies the
version constraints:
Dependency path 'my_package_name:app:unspecified' -->
'androidx.test.espresso:espresso-intents:3.2.0' -->
'androidx.test:core:1.2.0'
.....等等,有很多行
我该如何解决这个问题?为什么会这样?
为什么会这样?
发生这种情况是因为 androidx.test:core:1.2.0
:
的版本冲突
依赖项androidx.test.espresso:espresso-intents:3.2.0
使用核心库的 1.2.0 版。虽然还有另一个依赖项使用同一库的另一个版本,这让 Gradle 不高兴。如果你继续阅读那些 很多行 你会看到这个 另一个依赖项 是什么,但我高度怀疑它是 androidx.fragment:fragment-testing:1.2.0-alpha01
这取决于在核心库的 1.1.1 版上。
如何解决:
鉴于您确实需要升级您的浓缩咖啡,并且假设有问题的库是 fragment-testing,一个简单的解决方法是更改
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
到
debugImplementation ("androidx.fragment:fragment-testing:1.2.0-alpha01", {exclude group: 'androidx.test', module: 'core' })
我的所有仪器测试都有这些 gradle 依赖项:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
implementation 'androidx.fragment:fragment:1.1.0-alpha01'
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
一旦我将它们更新为:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
implementation 'androidx.fragment:fragment:1.2.0-alpha01'
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
和运行测试,我得到以下错误:
Cannot find a version of 'androidx.test:core' that satisfies the version constraints:
Dependency path 'my_package_name:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.2.0' --> 'androidx.test:core:1.2.0'
.....等等,有很多行
我该如何解决这个问题?为什么会这样?
为什么会这样?
发生这种情况是因为 androidx.test:core:1.2.0
:
依赖项androidx.test.espresso:espresso-intents:3.2.0
使用核心库的 1.2.0 版。虽然还有另一个依赖项使用同一库的另一个版本,这让 Gradle 不高兴。如果你继续阅读那些 很多行 你会看到这个 另一个依赖项 是什么,但我高度怀疑它是 androidx.fragment:fragment-testing:1.2.0-alpha01
这取决于在核心库的 1.1.1 版上。
如何解决:
鉴于您确实需要升级您的浓缩咖啡,并且假设有问题的库是 fragment-testing,一个简单的解决方法是更改
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
到
debugImplementation ("androidx.fragment:fragment-testing:1.2.0-alpha01", {exclude group: 'androidx.test', module: 'core' })