Android Architecture Components: Gradle sync error for dependency version

19,070

Solution 1

Apparently support-v4 was causing the conflict. In the case of this question, the Gradle dependency task wasn't working correctly, but for anyone else who runs into this issue:

./gradlew :app:dependencies will show the sub-dependencies used by your dependencies. Search the output of this command (changing app for your module name) for the dependency causing the conflict.

Solution 2

As @RedBassett mentions Support libraries depends on this lightweight import (runtime library) as explained at android developers documentation.

This is, android.arch.lifecycle:runtime:1.0.0 is spreading up in the dependency tree as a result of an internal api (transitive) import so in my case I only had to include extensions library as "api" instead of "implementation" so that it will override its version to the highest (1.1.1).

In conclusion, change

implementation "android.arch.lifecycle:extensions:1.1.1"

to

api "android.arch.lifecycle:extensions:1.1.1"

Solution 3

In your main build.gradle file

allprojects {
    ...

    configurations {
        all {
            resolutionStrategy {
                force "android.arch.lifecycle:runtime:1.1.1"
            }
        }
    }

}

This will enforce version 1.1.1

Solution 4

@RedBassett is right. However I was still having some problem excluding android.arch.lifecycle related sub dependencies.

In my case the conflict was caused in com.android.support:appcompat-v7:27.1.1.

This is how my gradle dependency looks like after excluding it.

implementation ('com.android.support:appcompat-v7:27.1.1') {
    exclude group: 'android.arch.lifecycle'
}


api "android.arch.lifecycle:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"

Also, you will have to add this exclude in every imported module.

Share:
19,070
RedBassett
Author by

RedBassett

I build thing for Web and Android. Sometimes.

Updated on June 24, 2022

Comments

  • RedBassett
    RedBassett about 2 years

    I'm trying to add ViewModel and LiveData to a Kotlin app. I have the following dependencies added to my module's build.gradle:

    implementation "android.arch.lifecycle:extensions:1.1.1"
    kapt "android.arch.lifecycle:compiler:1.1.1"
    testImplementation "android.arch.core:core-testing:1.1.1"
    

    I'm given the following error:

    Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.1.1) classpath. You should manually set the same version via DependencyResolution

    Removing the first line (extensions) fixes the issue, indicating that the error is coming from there, but I can't figure out why.