Cannot upgrade Android Gradle dependency 'androidx.annotation:annotation' to version 1.4.0

Viewed 149

Android Studio warned me there was a new version of the "androidx.annotation:annotation" package : 1.4.0. I was previously using version 1.3.0

extracts of my gradle file:

    compileSdkVersion 31
    defaultConfig {
        applicationId "org.cetaces.padoc"
        minSdkVersion 16
        targetSdkVersion 31
        versionCode 400009
        versionName getVersionName()
        setProperty("archivesBaseName", "PADOC_" + versionName)
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

and

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.fragment:fragment:1.5.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'com.opencsv:opencsv:5.6'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.annotation:annotation:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

    developmentImplementation platform('com.google.firebase:firebase-bom:30.2.0')
    developmentImplementation 'com.google.firebase:firebase-analytics'

    debugMemImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'

}

So I tried to upgrade to version 1.4.0 but when I build my project, I get this error:

Execution failed for task ':app:processDevelopmentDebugAndroidTestManifest'.
> Could not resolve all files for configuration ':app:developmentDebugAndroidTestRuntimeClasspath'.
   > Could not resolve androidx.annotation:annotation:1.4.0.
     Required by:
         project :app
      > Cannot find a version of 'androidx.annotation:annotation' that satisfies the version constraints:
           Dependency path 'dev:app:unspecified' --> 'androidx.annotation:annotation:1.4.0'
           Constraint path 'dev:app:unspecified' --> 'androidx.annotation:annotation:{strictly 1.3.0}' because of the following reason: developmentDebugRuntimeClasspath uses version 1.3.0
           Dependency path 'dev:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' --> 'androidx.annotation:annotation:1.0.0'
           Dependency path 'dev:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' --> 'androidx.test:core:1.4.0' --> 'androidx.annotation:annotation:1.0.0'
......

I guess I could just keep version 1.3.0, but I would like to understand what is happening. Could someone explain me the reason of this error?

Update 1: extract of the dependencies tree:

developmentDebugCompileClasspath - Resolved configuration for compilation for variant: developmentDebug
+--- androidx.multidex:multidex:2.0.0 -> 2.0.1
+--- androidx.multidex:multidex:{strictly 2.0.1} -> 2.0.1 (c)
+--- com.google.firebase:firebase-bom:30.2.0
|    +--- com.google.firebase:firebase-analytics:21.0.0 (c)
|    +--- com.google.firebase:firebase-common:20.1.1 (c)
|    \--- com.google.firebase:firebase-installations:17.0.1 (c)
+--- com.google.firebase:firebase-analytics -> 21.0.0
|    +--- com.google.android.gms:play-services-measurement:21.0.0
...

+--- androidx.viewpager2:viewpager2:{strictly 1.0.0} -> 1.0.0 (c)
+--- com.opencsv:opencsv:{strictly 5.6} -> 5.6 (c)
+--- com.google.android.gms:play-services-measurement:{strictly 21.0.0} -> 21.0.0 (c)
+--- com.google.android.gms:play-services-measurement-api:{strictly 21.0.0} -> 21.0.0 (c)
+--- com.google.android.gms:play-services-measurement-sdk:{strictly 21.0.0} -> 21.0.0 (c)
+--- androidx.annotation:annotation:{strictly 1.3.0} -> 1.3.0 (c)
...

Update 2: Digging a bit more in the dependencies tree, I found that for configuration "developmentDebug", the dependencies were OK (no FAILED):

developmentDebugCompileClasspath - Resolved configuration for compilation for variant: developmentDebug
+--- androidx.multidex:multidex:2.0.0 -> 2.0.1
+--- androidx.multidex:multidex:{strictly 2.0.1} -> 2.0.1 (c)
+--- com.google.firebase:firebase-bom:30.2.0
|    +--- com.google.firebase:firebase-analytics:21.0.0 (c)
|    +--- com.google.firebase:firebase-common:20.1.1 (c)
|    \--- com.google.firebase:firebase-installations:17.0.1 (c)
+--- com.google.firebase:firebase-analytics -> 21.0.0
|    +--- com.google.android.gms:play-services-measurement:21.0.0
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0
|    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0
|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0
|    |    |    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
...

but that for dependencies of configuration "developmentDebugAndroidTest", the dependency for annotations failed:

developmentDebugAndroidTestRuntimeClasspath - Resolved configuration for runtime for variant: developmentDebugAndroidTest
+--- androidx.test.ext:junit:1.1.3
|    +--- junit:junit:4.12
|    |    \--- org.hamcrest:hamcrest-core:1.3
|    +--- androidx.test:core:1.4.0
|    |    +--- androidx.annotation:annotation:1.0.0 FAILED
|    |    +--- androidx.test:monitor:1.4.0
|    |    |    \--- androidx.annotation:annotation:1.0.0 FAILED
|    |    \--- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.5.0
|    |         \--- androidx.annotation:annotation:1.1.0 FAILED
|    +--- androidx.test:monitor:1.4.0 (*)
|    \--- androidx.annotation:annotation:1.0.0 FAILED
+--- androidx.test:rules:1.4.0
|    \--- androidx.test:runner:1.4.0
|         +--- androidx.annotation:annotation:1.0.0 FAILED
|         +--- androidx.test:monitor:1.4.0 (*)
|         +--- androidx.test.services:storage:1.4.0
|         |    +--- androidx.test:monitor:1.4.0 (*)
|         |    \--- com.google.code.findbugs:jsr305:2.0.1
|         \--- junit:junit:4.12 (*)
+--- androidx.annotation:annotation:1.4.0 FAILED
+--- androidx.test.espresso:espresso-core:3.4.0
...

Is there anything to do except waiting for some fixes?

1 Answers

It would appear that one of your developmentImplementation dependencies requires 1.3.0 of that library:

Constraint path 'dev:app:unspecified' --> 'androidx.annotation:annotation:{strictly 1.3.0}' because of the following reason: developmentDebugRuntimeClasspath uses version 1.3.0

The simplest solutions is to see if you can upgrade your Firebase dependencies, or to stick with 1.3.0 of annotation.

Related