由于Firebase库,支持库的版本存在冲突

问题描述 投票:5回答:4

在Android Studio中创建新项目后,我在项目中添加了Firebase和Firebase消息,如manual中所述。

但是,在Gradle同步后,IDE会显示错误: 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

没有Firebase库,项目就可以正确构建。

项目级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
}

模块级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'

其余的文件没有改变。

版本:

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
android firebase android-support-library
4个回答
9
投票

使用gradle app: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 (*)

它显示Firebase拉取依赖关系com.android.support:support-v4:26.1.0,所以我覆盖了它,我的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: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'

它奏效了!


1
投票

添加错误消息中列出的任何库都会删除该消息。 (添加每个库后,您必须再次检查错误消息)。对我来说,我必须添加两个库:

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

    ...
}

不过,我仍然想知道为什么Firebase正在使用这些旧库,以及为什么如果Firebase实际需要那些旧库,这样的简单修复就可以了。


0
投票

在依赖项中添加它

implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:customtabs:28.0.0"
implementation 'com.android.support:mediarouter-v7:28.0.0'

-1
投票

我添加这两行并解决了我的问题:

实现'com.android.support:support-media-compat:28.0.0-beta01'

实现'com.android.support:support-v4:28.0.0-beta01'

© www.soinside.com 2019 - 2024. All rights reserved.