androidTestImplementation Google Truth 1.0 和实现 Google Guava 27.0.1 无法满足的版本约束

Unsatisfiable version constraints with androidTestImplementation Google Truth 1.0 and implementation Google Guava 27.0.1

简而言之

我无法获得最小的新 Android Studio 项目来构建具有以下添加的依赖项:

dependencies {
    ...
    implementation 'com.google.guava:guava:27.0.1-android'
    androidTestImplementation "com.google.truth:truth:1.0"
}

如何重现

我就是这样做的,当然还有其他方法。

  1. Android Studio 3.5.2 中:
    1. 文件新建新建项目...
  2. 创建新项目对话框中:
    1. Phone和平板电脑选项卡→添加否Activity下一步
    2. 名称,包名,保存位置:随便你想要
    3. 语言Java
    4. 最低API等级API 28
    5. 此项目将支持即时应用程序已禁用
    6. 完成
  3. ./app/build.gradle中:
    1. implementation 'com.google.guava:guava:27.0.1-android'androidTestImplementation "com.google.truth:truth:1.0" 添加到 dependencies
  4. ExampleInstrumentedTest.java
    1. 右键单击 class ExampleInstrumentedTest 和 select 运行 'ExampleInstrumentedTest'

预计
测试通过

实际
构建错误:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:preDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
   > Could not resolve org.checkerframework:checker-compat-qual:{strictly 2.5.2}.
     Required by:
         project :app
      > Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'org.checkerframework:checker-compat-qual:2.5.5'
           Constraint path 'sdfsf:app:unspecified' --> 'org.checkerframework:checker-compat-qual:{strictly 2.5.2}' because of the following reason: debugRuntimeClasspath uses version 2.5.2
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'

   > Could not resolve com.google.errorprone:error_prone_annotations:{strictly 2.2.0}.
     Required by:
         project :app
      > Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
           Constraint path 'sdfsf:app:unspecified' --> 'com.google.errorprone:error_prone_annotations:{strictly 2.2.0}' because of the following reason: debugRuntimeClasspath uses version 2.2.0
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'

   > Could not resolve org.checkerframework:checker-compat-qual:2.5.5.
     Required by:
         project :app > com.google.truth:truth:1.0
      > Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'org.checkerframework:checker-compat-qual:2.5.5'
           Constraint path 'sdfsf:app:unspecified' --> 'org.checkerframework:checker-compat-qual:{strictly 2.5.2}' because of the following reason: debugRuntimeClasspath uses version 2.5.2
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'

   > Could not resolve com.google.errorprone:error_prone_annotations:2.3.1.
     Required by:
         project :app > com.google.truth:truth:1.0
      > Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
           Constraint path 'sdfsf:app:unspecified' --> 'com.google.errorprone:error_prone_annotations:{strictly 2.2.0}' because of the following reason: debugRuntimeClasspath uses version 2.2.0
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'

   > Could not resolve org.checkerframework:checker-compat-qual:2.5.2.
     Required by:
         project :app > com.google.guava:guava:27.0.1-android
      > Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'org.checkerframework:checker-compat-qual:2.5.5'
           Constraint path 'sdfsf:app:unspecified' --> 'org.checkerframework:checker-compat-qual:{strictly 2.5.2}' because of the following reason: debugRuntimeClasspath uses version 2.5.2
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'

   > Could not resolve com.google.errorprone:error_prone_annotations:2.2.0.
     Required by:
         project :app > com.google.guava:guava:27.0.1-android
      > Cannot find a version of 'com.google.errorprone:error_prone_annotations' that satisfies the version constraints: 
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.truth:truth:1.0' --> 'com.google.errorprone:error_prone_annotations:2.3.1'
           Constraint path 'sdfsf:app:unspecified' --> 'com.google.errorprone:error_prone_annotations:{strictly 2.2.0}' because of the following reason: debugRuntimeClasspath uses version 2.2.0
           Dependency path 'sdfsf:app:unspecified' --> 'com.google.guava:guava:27.0.1-android' --> 'com.google.errorprone:error_prone_annotations:2.2.0'

我该如何解决这个构建问题?

解决方案非常简单。只需使用 'com.google.guava:guava:28.1-android' 而不是 'com.google.guava:guava:27.0.1-android'.