【问题标题】:Cannot find a version of 'com.google.code.findbugs:jsr305' that satisfies the version constraints找不到满足版本约束的“com.google.code.findbugs:jsr305”版本
【发布时间】:2019-06-28 10:53:12
【问题描述】:

当为 realse 生成签名 APK 时,我收到以下错误消息:

Cannot find a version of 'com.google.code.findbugs:jsr305' that satisfies the version constraints: 
   Dependency path 'XX:app:unspecified' --> 'androidx.test.espresso:espresso-core:3.1.2-alpha01' --> 'com.google.code.findbugs:jsr305:2.0.1'
   Constraint path 'XX:app:unspecified' --> 'com.google.code.findbugs:jsr305' strictly '1.3.9' because of the following reason: debugRuntimeClasspath uses version 1.3.9

这是我的应用程序:gradle

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.XX.XX"
    minSdkVersion 25
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}


 }

 dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.guava:guava:22.0-android'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
}

但是,如果我为调试而构建它可以正常工作,但是当我生成签名版本时,我收到了这条消息,我试图谷歌但似乎没有找到正确的答案。

【问题讨论】:

    标签: java android gradle build apk


    【解决方案1】:

    感谢 StackOverflow,这对我有用

    过去在 app.gradle 文件中

     android 
     {
        configurations.all 
        {
          resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
        }
     }
    

    【讨论】:

      【解决方案2】:

      试试这个

      android 
       {
          configurations.all 
          {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
          }
       }
      

      【讨论】:

        【解决方案3】:

        对于那些想知道如何解决依赖冲突问题的人。

        我的依赖:

        // 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 byCould 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")
            }
        

        我强制从org.robolectric:robolectric:4.3.1 中排除androidx.test:module,并使用androidx.test:coreandroix.test:runner 都需要的androidx.test:module:1.1.0

        guavalistener 也一样,我没有使用真相,所以我删除了它,但如果你确实需要它,你可以做同样的事情来排除/选择 必需的依赖项 您想要包含的内容

        决议 2

        如果您使用 roboelectric,您可能想排除一些依赖项,就像这里从 @finder2 java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-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'
        

        【讨论】:

        • "Resolutions 1" 选项适用于我的情况,谢谢。 (排除组:'com.google.code.findbugs',模块:'jsr305')
        【解决方案4】:

        试试看。 方法一: 在应用程序中注释掉或删除:与测试“androidTestImplementation”相关的 gradle 行; 方法二: 在 Android Studio 的“打开/编辑运行”窗口中,应选择“应用程序”选项。 enter image description here

        【讨论】:

          【解决方案5】:

          我不确定这个问题的确切原因。但是,在尝试了几个选项后,它自动开始工作了

          如果您正在使用 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"
          

          【讨论】:

            【解决方案6】:

            我今天遇到了类似的问题,发现了这个: https://github.com/trello/RxLifecycle/issues/154

            通过在依赖项添加下的(模块:应用程序)中编辑 Gradle 脚本 build.gradle 来解决我的问题:

            androidTestImplementation 'com.google.code.findbugs:jsr305:1.3.9'
            

            我最初尝试了不同的版本号,但收到一个错误,告诉我要使用哪个版本,因此您可能需要尝试几次。

            【讨论】:

            • 在使用stethoespresso-core 时,这两个依赖项都使用findbugs:2.0.1 时也相关,当我们还使用truth 时发生冲突,如here + solutions 所述,它已经移动到findbugs:3.0.2。使用您需要的版本忽略findbugs
            • 对于未来的读者,您可能想在这里查看我关于解决任何conflicted transitive dependency 包括findbugs, androidx.test:monitor, guava, etc 的步骤的其他答案
            猜你喜欢
            • 1970-01-01
            • 2019-03-26
            • 1970-01-01
            • 2019-09-18
            • 2020-01-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-15
            相关资源
            最近更新 更多