首页 > 解决方案 > Firebase 库必须使用确切的版本错误

问题描述

我想使用谷歌云消息推送通知到 android 应用程序。我阅读了以下文档并将firebase设置为我的应用程序。我的 gradle 构建成功,但在implementation 'com.google.firebase:firebase-core:16.0.1'某种程度上,我收到以下错误:

所有 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 17.1.0、16.2.0、16.1.1、16.0.1、16.0.0、15.0.1。示例包括 com.google.firebase:firebase-messaging:17.1.0 和 com.google.firebase:firebase-iid:16.2.0 less... (Ctrl+F1) 有一些库的组合,或工具和库,不兼容或可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译。

应用分级:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "notificationtest.com.test.notification"
    minSdkVersion 14
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
}


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

项目等级:

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

构建脚本 {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:4.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    maven {
        url "https://maven.google.com" // Google's Maven repository
    }
    google()
    jcenter()
}
}

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

有什么问题,我该如何解决?

标签: androidfirebase

解决方案


您添加了 2 个不同版本的 firebase 库。

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

请将其更改为相同的版本,即 15.0.2 我只使用此版本,直到现在都没有遇到问题。如果您愿意,您也可以使用 16.0.1 进行消息传递。谷歌可能没有发布 firebase-core 的 17 版。


推荐阅读