Google服务无法在Google Cloud Message

时间:2016-02-09 09:19:36

标签: android google-cloud-messaging

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

进行操作

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

  

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

     

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

     

E / GMPM:无法上传。应用程序测量已禁用

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

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'

我的项目gradle:

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文件中添加您的app id, Google console

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

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

1 个答案:

答案 0 :(得分:0)

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

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