2

简而言之

我无法使用以下添加的依赖项构建最小的新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. 手机和平板电脑选项卡 →不添加活动下一步
    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并选择运行'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'

如何解决此构建问题?

4

1 回答 1

2

解决方案简单得令人尴尬。只需使用'com.google.guava:guava:28.1-android'而不是'com.google.guava:guava:27.0.1-android'.

于 2019-11-07T07:25:25.357 回答