【发布时间】: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