Search code examples
androidandroidx

Cannot find a version of 'androidx.annotation:annotation' that satisfies the version constraints: Error when run androidTests


I have migrated to androidX recently and updated my targetSdkVersion to 29. After that I received the error when try to run 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

How can I solve it?


Solution

  • Finally I solved my issue. I added

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

    to my module level build.gradle.

    Optional: You may also need to add to fix compilation errors of your tests:

    android {
        ...
    
        // Gradle automatically adds 'android.test.runner' as a dependency.
        useLibrary 'android.test.runner'
    
        useLibrary 'android.test.base'
        useLibrary 'android.test.mock'
    }
    

    More info here https://developer.android.com/training/testing/set-up-project