找不到满足版本约束的'androidx.annotation:annotation'版本:运行androidTests时出错

问题描述 投票:0回答:3

我最近已迁移到androidX并将我的targetSdkVersion更新为29。之后,我在尝试运行androidTests时收到错误:

Cannot find a version of 'androidx.annotation:annotation' that satisfies the version constraints: 
   Dependency path 'lullabies-v3:mobile:unspecified' --> 'androidx.annotation:annotation:1.1.0'
   Dependency path 'lullabies-v3:mobile:unspecified' --> 'com.android.support:support-annotations:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
   Constraint path 'lullabies-v3:mobile:unspecified' --> 'androidx.annotation:annotation:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
   Dependency path 'lullabies-v3:mobile:unspecified' --> 'com.android.support:support-annotations:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled

如何解决?

android androidx
3个回答
11
投票

终于解决了我的问题。我添加了

implementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'

到我的模块级别 build.gradle。

可选:您可能还需要添加以修复测试的编译错误:

android {
    ...

    // Gradle automatically adds 'android.test.runner' as a dependency.
    useLibrary 'android.test.runner'

    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
}

更多信息在这里https://developer.android.com/training/testing/set-up-project


1
投票

我在尝试构建我的应用程序时遇到了同样的问题,将其添加到我的 build.gradle 中解决了它。

   dependencies {
    ...
    
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.versionedparcelable:versionedparcelable:1.0.0'
    androidTestImplementation 'androidx.versionedparcelable:versionedparcelable:1.0.0'
    implementation 'androidx.core:core:1.0.1'
    androidTestImplementation 'androidx.core:core:1.0.1'

 .... }

0
投票

就我而言,添加以下代码不足以解决注释库版本冲突。

implementation 'androidx.annotation:annotation:x.x.x'
androidTestImplementation 'androidx.annotation:annotation:x.x.x'

我还需要通过将以下代码添加到应用程序构建gradle文件来强制注释库的解析策略。

configurations.configureEach {
    resolutionStrategy.force 'androidx.annotation:annotation:x.x.x'
}
© www.soinside.com 2019 - 2024. All rights reserved.