3 回答

TA贡献1777条经验 获得超10个赞
我今天遇到了类似的问题,发现了这个: https ://github.com/trello/RxLifecycle/issues/154
通过在依赖项下的(模块:应用程序)中编辑 Gradle 脚本 build.gradle 来解决我的问题,添加:
androidTestImplementation 'com.google.code.findbugs:jsr305:1.3.9'
我最初尝试了一个不同的版本号,但收到一个错误,告诉我要使用哪个版本,所以您可能需要尝试几次。

TA贡献2037条经验 获得超6个赞
我不确定这个问题的确切原因。但是,在尝试了几个选项后,它自动开始工作
如果您正在使用 Room 组件,并为它编写测试。您需要添加以下依赖项。
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:2.1.0"
// Test helpers
testImplementation "androidx.room:room-testing:2.1.0"

TA贡献1906条经验 获得超10个赞
对于那些想知道如何解决依赖冲突问题的人。
我的依赖:
// Conflicted transitive dependency for androidx.test:monitor
- org.robolectric:robolectric -> androidx.test:monitor:1.2.0 (forced to use 1.1.0)
- androidx.test:core -> androidx.test:monitor:1.1.0
- androidx.test:runner -> androidx.test:monitor:1.1.0
// Conflicted transitive dependency for com.google.guava:listenablefuture
- androidx.test.ext:truth -> androidx.test:monitor:9999.0 (forced to use 1.0)
- androidx.work:work-runtime -> androidx.test:monitor:1.0
决议 1
我最终检查了Required by&Could not resolve [dependency] 关键字以确定并选择我想要包含的版本,例如:androidx.test:monitor:1.1.0&com.google.guava:listenablefuture:1.0然后通过执行以下操作排除其余版本:
androidTestImplementation(org.robolectric:robolectric:4.3.1) {
exclude(group = "androidx.test", module = "monitor")
exclude(group = "com.google.guava", module = "listenablefuture")
}
我正在强制排除androidx.test:module并org.robolectric:robolectric:4.3.1使用androidx.test:module:1.1.0两者所需的androidx.test:core& androix.test:runner。
对于guavalistener我没有使用真相也是如此,所以我将其删除,但如果您确实需要它,您可以执行相同操作来排除/选择您想要包含的所需依赖项
决议 2
如果您使用 roboelectric,您可能想从 @finder2 中排除一些依赖项,就像这里一样java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-任务-2.1.3.jar
上述方法是一个修补程序,您可能还需要仔细选择要使用的传递依赖项,或者只是删除不需要的依赖项(truth以我为例)
以下是修复依赖冲突后的错误构建输出findbugs,通过上述方法,我能够修复它。
* What went wrong:
Could not determine the dependencies of task ':app:preDevDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:devDebugAndroidTestRuntimeClasspath'.
> Could not resolve androidx.test:monitor:{strictly 1.1.0}.
Required by:
project :app
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve androidx.test:monitor:1.2.0.
Required by:
project :app > org.robolectric:robolectric:4.3.1
project :app > org.robolectric:robolectric:4.3.1 > org.robolectric:shadows-framework:4.3.1
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve androidx.test:monitor:1.1.0.
Required by:
project :app > androidx.test:core:1.0.0
project :app > androidx.test:runner:1.1.0
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve com.google.guava:listenablefuture:1.0.
Required by:
project :app > androidx.work:work-runtime:2.2.0
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.work:work-runtime:2.2.0' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test.ext:truth:1.0.0' --> '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 :app > androidx.test.ext:truth:1.0.0 > com.google.guava:guava:27.0.1-jre
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.work:work-runtime:2.2.0' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test.ext:truth:1.0.0' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
添加回答
举报