android - Could not resolve com.google.guava:listenablefuture:{strictly 1.0} when testing WorkManager
问题描述
I have an app that uses WorkManager for some scheduled tasks, and I'm testing it with the aid of a bunch of different frameworks. It seems relevant to this issue that I'm using robolectric and of course androidx.work:work-testing .
I'm able to run unit tests successfully, but when I attempt to run instrumentation tests, Calculate task graph
fails with
Could not determine the dependencies of task ':myModule:mergeDebugAndroidTestResources'.
> Could not resolve all task dependencies for configuration ':myModule:debugAndroidTestRuntimeClasspath'.
> Could not resolve com.google.guava:listenablefuture:{strictly 1.0}.
Required by:
project :myModule
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'MyApp:myModule:unspecified' --> 'androidx.work:work-testing:2.0.1' --> 'androidx.work:work-runtime:2.0.1' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'MyApp:myModule:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: debugRuntimeClasspath uses version 1.0
Dependency path 'MyApp:myModule:unspecified' --> 'org.robolectric:robolectric:4.2.1' --> 'org.robolectric:resources:4.2.1' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
> Could not resolve com.google.guava:listenablefuture:1.0.
Required by:
project :myModule > androidx.work:work-runtime:2.0.1
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'MyApp:myModule:unspecified' --> 'androidx.work:work-testing:2.0.1' --> 'androidx.work:work-runtime:2.0.1' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'MyApp:myModule:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: debugRuntimeClasspath uses version 1.0
Dependency path 'MyApp:myModule:unspecified' --> 'org.robolectric:robolectric:4.2.1' --> 'org.robolectric:resources:4.2.1' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
> Could not resolve com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava.
Required by:
project :myModule > org.robolectric:robolectric:4.2.1 > org.robolectric:resources:4.2.1 > com.google.guava:guava:27.0.1-jre
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'MyApp:myModule:unspecified' --> 'androidx.work:work-testing:2.0.1' --> 'androidx.work:work-runtime:2.0.1' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'MyApp:myModule:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: debugRuntimeClasspath uses version 1.0
Dependency path 'MyApp:myModule:unspecified' --> 'org.robolectric:robolectric:4.2.1' --> 'org.robolectric:resources:4.2.1' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Tried adding guava "com.google.guava:guava:27.0.1-android"
(against my will) as a testImplementation and an androidTestImplementation and got a Dependency path 'MyApp:mymodule:unspecified' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
instead of the line Dependency path 'MyApp:myModule:unspecified' --> 'org.robolectric:robolectric:4.2.1' --> 'org.robolectric:resources:4.2.1' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
Some dependencies in my module's build.gradle:
implementation "androidx.work:work-runtime-ktx:2.0.1"
testImplementation "org.robolectric:robolectric:4.2.1"
androidTestImplementation "org.robolectric:robolectric:4.2.1"
androidTestImplementation "androidx.work:work-testing:2.0.1"
androidTestImplementation "androidx.work:work-testing:2.0.1"
解决方案
对我来说,Truth 和 androidx.work:work-runtime 之间存在相同的错误
并用以下固定
androidTestImplementation 'com.google.truth:truth:1.0.1', { exclude group: 'com.google.guava', module:'listenablefuture'}
api 'com.google.guava:listenablefuture:1.0'
用于机器人电动
androidTestImplementation "org.robolectric:robolectric:4.2.1", { exclude group: 'com.google.guava', module:'listenablefuture'}
api 'com.google.guava:listenablefuture:1.0'
推荐阅读
- javascript - 函数内的 Javascript 暂停
- android - 您通常如何为仪器单元测试执行模拟?
- python - DynamoDB:使用 Python 导入大数据
- c# - SQL 查询的结果永远不会返回 null;
- typescript - TypeScript 导入语句在 Expo 项目中找不到 Firebase 模块
- flutter - Flutter AudioService 每次获取 Fetch Url
- python - Flask 知道主应用程序中的类,但不知道 html 模板中的类
- javascript - 如何检查反应组件是否分离
- c# - 为什么我会因 C# 的 codechef 的 XORGM(XOR 游戏)问题而获得 TLE
- python - drf 用户序列化程序返回自定义数据