【问题标题】:Firebase Push Notifications - Google Services IssueFirebase 推送通知 - Google 服务问题
【发布时间】:2017-03-18 21:16:25
【问题描述】:

我正在尝试安装推送通知并按照 firebase 上的说明进行操作,但在我的 gradle 文件中添加这些行并尝试同步后,我收到以下错误。

错误:任务 ':app:processDebugGoogleServices' 执行失败。 找不到与包名称“com.project.myproject”匹配的客户端

我下载了 google-services.json 文件并将其放在我的项目下的应用程序文件夹中。

这是我的成绩文件

应用程序

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        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
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

模块

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.project.myproject"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 39
        versionName "1.0.0.39"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 你能发布你的树文件层次结构吗?你检查你的 google-services.json package_name 是否和你的 applicationId 一样?
  • 是的包名是一样的。我花了一个小时寻找这个问题,发现了类似的问题,但没有一个答案对我有用。但问题。 google-services.json 是否只应该在 APP 文件夹中?或者其他地方也......用于调试等?
  • 文件树层次结构?在项目视图下?我的 app 文件夹中只有一个 google 服务文件
  • 如果您不需要为每种口味使用不同的文件,您可以只使用一个。如果您需要它,您应该为每个项目创建一个不同的项目(在 firebase 控制台中),然后使用相应的 .json 来获得正确的风格:stackoverflow.com/a/39305974/1423773

标签: android android-studio firebase push-notification google-play-services


【解决方案1】:

使用这个,

    compile 'com.google.firebase:firebase-auth:9.4.0'
    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-config:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'

您特别需要的服务。在这里找到它们的列表

compile 'com.google.android.gms:play-services-analytics:9.4.0'
compile 'com.google.android.gms:play-services-appinvite:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-plus:9.4.0'
compile 'com.google.android.gms:play-services-drive:9.4.0'

另外,您需要在应用程序 gradle 的最后一行应用播放服务插件:

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

在 gradle 中也检查这个,

  dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha6' 
}

还有一个重要的音符是,

google-services.json文件一般放在app/目录下,

app/google-services.json

注意:

在您的 google-services.json 中检查您的软件包名称

示例 (provided by Muhammed Fasil):

"client_info": {
    "mobilesdk_app_id": "1:6596814400689:android:65d6f25f5006145",
    "android_client_info": {
      "package_name": "com.my.app.package.name"
    }

【讨论】:

  • 如果你密切关注这个问题,你会发现用户几乎做了你提到的所有事情,你也应该在你得到“你的”答案的地方给予正确的评价;)stackoverflow.com/a/38198021/1423773
  • 谢谢。我只是查看了以上所有内容,但到目前为止还没有运气。
猜你喜欢
  • 1970-01-01
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-02
  • 2017-10-25
相关资源
最近更新 更多