【问题标题】:GoogleService failed to initialize in Google Cloud MessageGoogleService 未能在 Google Cloud 消息中初始化
【发布时间】:2016-02-09 09:19:36
【问题描述】:

我在我的 Android 应用程序中使用谷歌云消息。我按照步骤here

当我运行应用程序时,logcat 会显示警告消息:

E/GMPM:GoogleService 初始化失败,状态:10,缺少预期的资源:用于初始化 Google 服务的“R.string.google_app_id”。可能的原因是缺少 google-services.json 或 com.google.gms.google-services gradle 插件。

E/GMPM:未设置调度程序。不记录错误/警告。

E/GMPM:无法上传。应用衡量功能已停用

但我仍然可以获取令牌,当我使用 Google gcm 示例代码测试推送(gcmsender)时,它工作正常(我可以接收推送),我添加了由 Google 生成的名为“google-services”的配置文件.json”添加到我的项目中, 和我的应用程序:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'}

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

我的项目毕业:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath 'com.google.gms:google-services:1.3.0-beta4'

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

我不明白为什么 logcat 上会显示警告消息,我按照步骤操作,应用程序运行良好,有人知道吗?

编辑:问题已解决, 只需在 string.xml 文件中添加您的应用程序 ID, Google console

找到“project_id”,并复制到你的 string.xml

<!-- App id -->
<string name="google_app_id">your project id</string>

【问题讨论】:

  • 您是否尝试在您的 string.xml 文件中定义 google_app_id?
  • 不,什么是 google_app_id?我在 GCM 指南页面中没有找到这个
  • 只需定义您将从谷歌控制台获得的应用 ID。
  • 哇!警告消失了!谢谢!
  • 欢迎。 :) 我很高兴它帮助了你

标签: android google-cloud-messaging


【解决方案1】:

添加您的应用 ID(从 google 控制台获取)并将其添加到 string.xml

<!-- App id -->
<string name="google_app_id">appId</string>

【讨论】:

  • 您在开发者控制台的哪个位置找到应用 ID?还是您说的是 Google API 项目编号?
  • @Dimitar Darazhanski 是的,它是 Google API 项目编号。
  • 有没有办法添加多个项目编号?否则我必须将所有 API 项目合并为一个。
  • @DimitarDarazhanski 为什么要添加多个项目?您可以在控制台中添加多个项目。
  • 我不想。但这就是我几年前开始的方式。现在将它们合并为一个会很头疼。
猜你喜欢
  • 2016-03-25
  • 2020-08-26
  • 1970-01-01
  • 2021-08-03
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多