Android 测试WorkManager时无法解析com.google.guava:listenablefuture:{1.0}
我有一个应用程序,它使用WorkManager完成一些预定任务,我正在用一系列不同的框架进行测试。我使用的是robolectric,当然还有androidx。工作:工作测试 我能够成功地运行单元测试,但当我尝试运行插装测试时,Android 测试WorkManager时无法解析com.google.guava:listenablefuture:{1.0},android,robolectric,android-workmanager,android-guava,Android,Robolectric,Android Workmanager,Android Guava,我有一个应用程序,它使用WorkManager完成一些预定任务,我正在用一系列不同的框架进行测试。我使用的是robolectric,当然还有androidx。工作:工作测试 我能够成功地运行单元测试,但当我尝试运行插装测试时,Calculate task graph会失败 Could not determine the dependencies of task ':myModule:mergeDebugAndroidTestResources'. > Could not resolve a
Calculate task graph
会失败
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'
尝试添加番石榴“com.google.guava:guava:27.0.1-android”
(违背我的意愿)作为一个testImplementation和一个androidTestImplementation,得到了一个依赖路径'MyApp:mymodule:unspecified'>'com.google.guava:guava:27.0.1-jre'>'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
而不是依赖路径'MyApp:mymodule:unspecified'>>‘org.roblectric:roblectric:4.2.1’-->‘org.roblectric:resources:4.2.1’-->‘com.google.guava:guava:27.0.1-jre’-->‘com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava’
我的模块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之间也存在同样的错误 并固定在下面
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'
面对同样的问题。尝试在alpha中使用最新的androidX。不确定当我的代码没有更改并且我没有在gradle依赖项中使用+时,什么东西坏了