【问题标题】:Android: which version of com.google.android.gms:play-services will be compatible to com.google.firebase:firebase-messaging?Android:哪个版本的 com.google.android.gms:play-services 将与 com.google.firebase:firebase-messaging 兼容?
【发布时间】:2017-07-11 11:26:22
【问题描述】:

在this tutorial 之后,我尝试将 Firebase SDK 集成到一个 Android 应用程序中(实际上它是一个 ReactNative-Application 但在这个级别上它并不重要) 但遇到了几个编译器 -使用 firebase-messaging 中的类时出错。

编译器声明只有 9.0.0 版本相互兼容。但是这些版本不能与教程中列出的客户端代码一起使用。

有些人(A、B)写道,firebase-messaging 必须在 V 9.2.1 或 10.0.1 中编译,但 Android Studio 抱怨这些版本与 google-play- 不兼容服务 10.0.1。 当我将 google-play-services 增加到 11.0.1(没有可用的 10.0 或 9.2)时,也会发生同样的情况:

Found com.google.firebase:firebase-core:9.2.1, but version 9.0.0 is needed for the google-services plugin.
Found com.google.firebase:firebase-messaging:9.2.1, but version 9.0.0 is needed for the google-services plugin.
:app:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of 
the google-services plugin (information about the latest version is available at 
https://bintray.com/android/android-tools/com.google.gms.google-services/) 
or updating the version of com.google.android.gms to 9.0.0.

这些是编译器错误:

1。无法访问 AbstractSafeParcelable

错误:无法访问 AbstractSafeParcelable i.putExtra("数据", remoteMessage);

package com.cooblr.notification;

import android.content.Intent;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent i = new Intent("Message");
        i.putExtra("data", remoteMessage);
        sendOrderedBroadcast(i, null);
    }
}

2。找不到 AbstractSafeParcelable

类文件 com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable 没找到

等等……

分级:

./android/build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:3.1.0'

./android/app/build.gradle:

compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-core:9.2.1'
compile 'com.google.firebase:firebase-messaging:9.2.1'

【问题讨论】:

  • 我在 project/build.gradle 中使用类路径 'com.google.gms:google-services:3.0.0' 并编译 'com.google.firebase:firebase-messaging:9.6.0, 编译'com.google.android.gms:play-services-maps:9.6.0',编译 'com.google.firebase:firebase-database:9.6.0'
  • 这里 firebase.google.com/docs/android/setup 是 Firebase 和类路径 'com.google.gms:google-services:3.1.0' 的可用库
  • @eurosecom thx,但这会导致:找到 com.google.android.gms:play-services:9.6.0,但 google-services 插件需要 9.0.0 版本。找到 com.google.android.gms:play-services-maps:9.6.0,但 google-services 插件需要 9.0.0 版本。 :app:processDebugGoogleServices 失败
  • 您的所有 Play 服务和 Firebase 依赖项都应始终处于完全相同的版本。撰写本文时的最新版本是 11.0.2。 google-services 插件的最新版本是 3.1.0。

标签: android firebase firebase-cloud-messaging


【解决方案1】:

您必须在您的应用级别 gradle 中添加以下内容

dependencies {
 compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'

在项目级别的gradle中

 dependencies {
        classpath 'com.google.gms:google-services:3.0.0'

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

我在我当前的应用程序中使用它,所以它的工作.goodluck

【讨论】:

  • 附加说明:请永远不要依赖“com.google.android.gms:play-services”,因为这会将每个 google 移动库添加到您的项目中。您应该始终依赖“com.google.android.gms:play-services-SPECIFIC-LIBRARY”或“com.google.firebase:firebase-LIBRARY”
猜你喜欢
  • 1970-01-01
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 2016-08-13
  • 2016-01-06
相关资源
最近更新 更多