'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 1:[1]

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

Solution 2:[2]

I was having same issue when trying to build my app, adding this to my build.gradle solved it.

   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'

 .... }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 kader gomez