【问题标题】:How to import GcmListenerService in android studio?如何在 android studio 中导入 GcmListenerService?
【发布时间】:2017-08-06 22:43:34
【问题描述】:

我正在创建 android 应用程序“GoogleCloudMessaging”。我发现很多人正在使用“GcmListenerService”,而旧方法“GCMIntentService”现在已被弃用。 我已经安装了 Google Play 服务并将其添加到依赖项中。 但是当我尝试导入时

 import com.google.android.gms.gcm.GcmListenerService;

它给出错误“无法解析符号”。 如何导入类? 我参考https://developers.google.com/android/reference/com/google/android/gms/gcm/GoogleCloudMessaginghttps://developers.google.com/android/reference/com/google/android/gms/gcm/GcmListenerService.html#GcmListenerService() 跟着事情走,还是没能解决问题。

【问题讨论】:

标签: android google-cloud-messaging


【解决方案1】:

如果您已将 Google Play 服务添加到您的依赖项中,则问题可能出在其版本上。

尝试将行(在您的 build.gradle 中)更新为:

compile 'com.google.android.gms:play-services:7.5.0'

然后同步您的项目。

【讨论】:

  • GCMListenerService是7.5.0加入的,以前的版本不会有。
  • compile 'com.google.android.gms:play-services:7.3.0' 这个版本我已​​经添加了。我已经从 SDK->extras->google play services 下载了它。
【解决方案2】:

你必须包括

compile 'com.google.android.gms:play-services-gcm:11.0.4'

在您的 build.gradle 文件中。

【讨论】:

    猜你喜欢
    • 2015-04-17
    • 2018-10-06
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 2013-12-09
    • 2023-04-02
    相关资源
    最近更新 更多