Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflicting versions of the support library because of the Firebase library

After creating a new project in Android Studio, I added Firebase and Firebase-messaging to the project, as described in the manual.

However, after Gradle sync, the IDE displays an error:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0-beta01, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0-beta01 and com.android.support:support-media-compat:26.1.0

Without Firebase libraries, the project is built correctly.

Project-level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module-level build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "ru.sabernyan.myapplication"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'

    implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'

    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.android.support:design:28.0.0-beta01'
}

apply plugin: 'com.google.gms.google-services'

The rest of the files were not changed.

Versions:

Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.17.11-zen1
like image 819
saber-nyan Avatar asked Aug 01 '18 10:08

saber-nyan


2 Answers

Using gradle app:dependencies, I got a list of dependencies:

debugCompileClasspath - Resolved configuration for compilation for variant: debug
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.30
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.30
|         \--- org.jetbrains:annotations:13.0
+--- com.google.firebase:firebase-core:16.0.1
|    +--- com.google.firebase:firebase-analytics:16.0.1
|    |    +--- com.google.android.gms:play-services-basement:15.0.1
|    |    |    \--- com.android.support:support-v4:26.1.0
|    |    |         +--- com.android.support:support-compat:26.1.0 -> 28.0.0-beta01
|    |    |         |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- com.android.support:collections:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- android.arch.lifecycle:runtime:1.1.1
|    |    |         |    |    +--- android.arch.lifecycle:common:1.1.1
|    |    |         |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
|    |    |         |    |    +--- android.arch.core:common:1.1.1
|    |    |         |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
|    |    |         |    \--- com.android.support:versionedparcelable:28.0.0-beta01
|    |    |         |         \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         +--- com.android.support:support-media-compat:26.1.0 -> 28.0.0-beta01
|    |    |         |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    \--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         +--- com.android.support:support-core-utils:26.1.0 -> 28.0.0-beta01
|    |    |         |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:documentfile:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- com.android.support:loader:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    +--- android.arch.lifecycle:livedata-core:1.1.1
|    |    |         |    |    |    +--- android.arch.lifecycle:common:1.1.1 (*)
|    |    |         |    |    |    +--- android.arch.core:common:1.1.1 (*)
|    |    |         |    |    |    \--- android.arch.core:runtime:1.1.1
|    |    |         |    |    |         +--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
|    |    |         |    |    |         \--- android.arch.core:common:1.1.1 (*)
|    |    |         |    |    \--- android.arch.lifecycle:viewmodel:1.1.1
|    |    |         |    |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
|    |    |         |    +--- com.android.support:localbroadcastmanager:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    \--- com.android.support:print:28.0.0-beta01
|    |    |         |         \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         +--- com.android.support:support-core-ui:26.1.0 -> 28.0.0-beta01
|    |    |         |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:customview:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:viewpager:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    \--- com.android.support:customview:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:coordinatorlayout:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    \--- com.android.support:customview:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:drawerlayout:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    \--- com.android.support:customview:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:slidingpanelayout:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    \--- com.android.support:customview:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:interpolator:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    +--- com.android.support:swiperefreshlayout:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    |    \--- com.android.support:interpolator:28.0.0-beta01 (*)
|    |    |         |    +--- com.android.support:asynclayoutinflater:28.0.0-beta01
|    |    |         |    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         |    |    \--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |         |    \--- com.android.support:cursoradapter:28.0.0-beta01
|    |    |         |         \--- com.android.support:support-annotations:28.0.0-beta01
|    |    |         \--- com.android.support:support-fragment:26.1.0 -> 28.0.0-beta01
|    |    |              +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    |    |              +--- com.android.support:support-core-ui:28.0.0-beta01 (*)
|    |    |              +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
|    |    |              +--- com.android.support:support-annotations:28.0.0-beta01
|    |    |              +--- com.android.support:loader:28.0.0-beta01 (*)
|    |    |              \--- android.arch.lifecycle:viewmodel:1.1.1 (*)
|    |    +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
|    |    +--- com.google.android.gms:play-services-stats:15.0.1
|    |    |    \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
|    |    +--- com.google.firebase:firebase-analytics-impl:[16.1.1] -> 16.1.1
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:15.0.1
|    |    |    |    \--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
|    |    |    +--- com.google.android.gms:play-services-stats:15.0.1 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:15.0.1
|    |    |    |    \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
|    |    |    +--- com.google.firebase:firebase-common:16.0.0
|    |    |    |    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    |    |    |    \--- com.google.android.gms:play-services-tasks:15.0.1 (*)
|    |    |    \--- com.google.firebase:firebase-iid:16.0.0 -> 16.2.0
|    |    |         +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    |    |         +--- com.google.android.gms:play-services-stats:15.0.1 (*)
|    |    |         +--- com.google.android.gms:play-services-tasks:15.0.1 (*)
|    |    |         +--- com.google.firebase:firebase-common:16.0.0 (*)
|    |    |         \--- com.google.firebase:firebase-iid-interop:16.0.0
|    |    |              +--- com.google.android.gms:play-services-base:15.0.1
|    |    |              |    +--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
|    |    |              |    \--- com.google.android.gms:play-services-tasks:[15.0.1] -> 15.0.1 (*)
|    |    |              \--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    |    \--- com.google.firebase:firebase-common:16.0.0 (*)
|    \--- com.google.firebase:firebase-measurement-connector-impl:16.0.1
|         +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|         +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
|         +--- com.google.firebase:firebase-analytics:[16.0.1] -> 16.0.1 (*)
|         +--- com.google.firebase:firebase-analytics-impl:[16.1.1] -> 16.1.1 (*)
|         +--- com.google.firebase:firebase-common:16.0.0 (*)
|         \--- com.google.firebase:firebase-measurement-connector:16.0.0
|              \--- com.google.android.gms:play-services-basement:15.0.1 (*)
+--- com.google.firebase:firebase-messaging:17.1.0
|    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    +--- com.google.android.gms:play-services-tasks:15.0.1 (*)
|    +--- com.google.firebase:firebase-common:16.0.0 (*)
|    +--- com.google.firebase:firebase-iid:[16.2.0] -> 16.2.0 (*)
|    \--- com.google.firebase:firebase-measurement-connector:16.0.0 (*)
+--- com.android.support:appcompat-v7:28.0.0-beta01
|    +--- com.android.support:support-annotations:28.0.0-beta01
|    +--- com.android.support:support-compat:28.0.0-beta01 (*)
|    +--- com.android.support:collections:28.0.0-beta01 (*)
|    +--- com.android.support:cursoradapter:28.0.0-beta01 (*)
|    +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
|    +--- com.android.support:support-fragment:28.0.0-beta01 (*)
|    +--- com.android.support:support-vector-drawable:28.0.0-beta01
|    |    +--- com.android.support:support-annotations:28.0.0-beta01
|    |    \--- com.android.support:support-compat:28.0.0-beta01 (*)
|    \--- com.android.support:animated-vector-drawable:28.0.0-beta01
|         +--- com.android.support:support-vector-drawable:28.0.0-beta01 (*)
|         \--- com.android.support:support-core-ui:28.0.0-beta01 (*)
+--- com.android.support:support-media-compat:28.0.0-beta01 (*)
+--- com.android.support.constraint:constraint-layout:1.1.2
|    \--- com.android.support.constraint:constraint-layout-solver:1.1.2
\--- com.android.support:design:28.0.0-beta01
     +--- com.android.support:support-annotations:28.0.0-beta01
     +--- com.android.support:support-compat:28.0.0-beta01 (*)
     +--- com.android.support:support-core-ui:28.0.0-beta01 (*)
     +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
     +--- com.android.support:support-fragment:28.0.0-beta01 (*)
     +--- com.android.support:transition:28.0.0-beta01
     |    +--- com.android.support:support-annotations:28.0.0-beta01
     |    \--- com.android.support:support-compat:28.0.0-beta01 (*)
     +--- com.android.support:appcompat-v7:28.0.0-beta01 (*)
     +--- com.android.support:cardview-v7:28.0.0-beta01
     |    \--- com.android.support:support-annotations:28.0.0-beta01
     \--- com.android.support:recyclerview-v7:28.0.0-beta01
          +--- com.android.support:support-annotations:28.0.0-beta01
          +--- com.android.support:support-compat:28.0.0-beta01 (*)
          \--- com.android.support:support-core-ui:28.0.0-beta01 (*)

It shows that Firebase pulls the dependency com.android.support:support-v4:26.1.0, so I overwritten it, and my build.gradle now looks like this:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "ru.sabernyan.myapplication"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'

    implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
    implementation 'com.android.support:support-v4:28.0.0-beta01' // <= dependency overwritten
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'

    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.android.support:design:28.0.0-beta01'
}

apply plugin: 'com.google.gms.google-services'

And it worked!

like image 163
saber-nyan Avatar answered Sep 18 '22 16:09

saber-nyan


Adding any libraries listed in the error message gets rid of the message. (You have to check the error message again after adding each library). For me, I had to add two libraries:

dependencies {
    ...

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'

    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'com.android.support:support-v4:28.0.0'            // <-- added
    implementation 'com.android.support:support-media-compat:28.0.0'  // <-- added

    ...
}

I'd still like to know, though, why Firebase is using these old libraries and why a simple fix like this works if Firebase actually needs those old libraries.

like image 35
Suragch Avatar answered Sep 18 '22 16:09

Suragch