android - 如何将 Firebase RealtimeDatabase 和 FCM 放在一起

标签 android firebase firebase-realtime-database firebase-cloud-messaging

我猜我可能有一些版本问题?我在用

实现 'com.google.firebase:firebase-messaging:15.0.2'

一切正常,现在我想添加 RealtimeDatabase

Android Studio 助手建议:

implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.firebase:firebase-database:11.8.0'

官方指南建议

implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.firebase:firebase-database:16.0.1'

两个结果:请通过更新 google-services 插件的版本...或将 com.google.android.gms 的版本更新为 15.0.2 来修复版本冲突。

我知道我可能必须调整他们的版本,但我得到了

Could not find com.google.firebase:firebase-messaging:16.0.1.

Could not find com.google.firebase:firebase-database:15.0.2.

// If I use All official latest
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1' 

Could not find com.google.firebase:firebase-core:17.0.0.

那么我怎样才能把它们放在一起呢?

官方网站: 出现“找不到”错误?确保您已将 Google maven 存储库添加到您的根 build.gradle

但我做到了。 (是吗?)这是我的 app.gradle

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url "https://maven.google.com" }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.10.1'
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

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

ext {
    roomVersion = '1.0.0'
    archLifecycleVersion = '1.1.0'
}

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

最佳答案

改变这个:

 classpath 'com.google.gms:google-services:3.1.1'

进入这个:

 classpath 'com.google.gms:google-services:4.0.1'

并使用以下依赖项:

implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'

更多信息在这里:Firebase Release notes

关于android - 如何将 Firebase RealtimeDatabase 和 FCM 放在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50983610/

相关文章:

java - 如何在Java中动态添加charsequence []中的数据?

android - 来自 pictureTaken 的图像被拉伸(stretch)

java - 如何以编程方式使用 JSON 文件中的数据填充 Firebase?

ios - 在 Xcode 中更改 Firebase Crashlytics 的 bundle ID

android - 为什么我的搜索栏左右两侧有空格?

android - 如何在 Android 中以编程方式向联系人添加电话号码?

firebase - 使用 map 的 Flutter Firestore where 子句

ios - Firebase 查询无法正常工作

firebase - 在对象 [object Object] 中找不到函数 FirebaseApp.getDatabaseByUrl

javascript - 云函数 HTTPS 触发器生成唯一的用户 ID