All com.android.support libraries must use the exact same version specification after adding firebase

My android Studio shows this error.

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:15.0.0'

3 answers

  • answered 2018-05-16 05:49 Vladyslav Matviienko

    It themes like com.google.firebase:firebase-core:15.0.0 depends on older support library varsion (26.1.0).
    There already is 15.0.2 version released, so you could try to:

    • use 15.0.2 version of firebase core. Probably it is based on latest support lib
    • ignore this message, as it is a warning, not an error, and probably your app would work fine with it. (not recommended, but could work)
    • downgrade your used support libs version to 26.1.0 so they are the same version. At least until google releases firebase based on the latest support lib version. (recommended way if #1 didn't work)

  • answered 2018-05-16 05:59 ישו אוהב אותך

    Instead of downgrading or excluding the support library, you can solve the problem by overriding the support library. You can override the support library by adding the dependency which is in the error:

    implementation "com.android.support:animated-vector-drawable:27.1.1"
    

    For argumentation about this answer, you can see the following issues in Firebase:

  • answered 2018-05-16 06:05 parekhkruti26

    When you run ./gradlew :app:dependencies, you come to know the transitive dependencies of libraries one has included in their gradle.

    From that hierarchy view, one can find out which libraries are depending on older versions and exclude them in gradle as shown below:

     exclude group:'com.android.support'//as an example support library is excluded
    

    As far as this question is concerned, it can be done like this:

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation ('com.google.firebase:firebase-core:15.0.2'){
        exclude group:'com.android.support'
    }
    

    Here support library is excluded as firebase core was depending on older versions, creating a conflict.

    NOTE:

    If your dependencies don't include the libraries that you have excluded but the dependency from which you have excluded needs it, you can add the excluded library in gradle with your compatible version.