无法解析com.google.android.gcm.GCMBaseIntentService; Android工作室 [英] Cannot resolve com.google.android.gcm.GCMBaseIntentService; Android studio

查看:194
本文介绍了无法解析com.google.android.gcm.GCMBaseIntentService; Android工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b


  1. 教程实施GCM客户端,有链接下载演示的完整源代码。

  2. 已下载作为参考,在build.gradle中添加了google_play_service库。

  3. 做了一些推荐的更改,例如SENDER_ID,SERVER_URL,.. etc。 >使用gradle同步项目并发生此错误。

我如何解决问题!


  1. 经过很多google之后,我发现这个类不在google_play_service库中,但它在gcm.jar中,现在不推荐使用。
    我不知道为什么google给出了旧代码的链接,并解释了文档中的最新代码。
  2. 然后我包含gcm.jar
  3. 错误消失了,得到了推送通知:)

希望这会对遇到麻烦的人有所帮助!

>

我的老问题

我是android studio的新手。我不明白build.gradle。今天我按照 https://developer.android提供的说明执行gcm-demo-client。 com / google / gcm / client.html
但是,当我从建议的导入它时

  / home / shani / Desktop / gcm-76908409d9d5 / samples / gcm -demo-client1 / app / src / main / java / com / google / android / gcm / demo / app / GCMIntentService.java:28:error:can not find symbol 
import com.google.android.gcm.GCMBaseIntentService ;
^
symbol:class GCMBaseIntentService
location:package com.google.android.gcm

还有其他25个错误。在Google上进行了一些搜索之后,我发现它是因为我没有在build.gradle中添加google play服务库。

然后我添加了库:
下面是我的build.gradle文件

  apply plugin:'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion21.1.2

defaultConfig {
applicationIdcom.google.android.gcm.demo.app
minSdkVersion 8
targetSdkVersion 16
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard -rules.txt'
}
依赖关系{
compilecom.google.android.gms:play-services:3.1。+
}
}

现在,当我点击同步链接时,我获得了Build Success。但是,当我尝试在真正的设备上运行上面的错误来。我不知道我做错了什么。请给我解决方案,我真的花了两天实施gcm演示应用程序。 如果您使用最新版本的 7.0.0 版本,则会发生这种情况。由于方法计数(65536)的上限是如何的,他们将Google Play服务进一步细分为6.5。



无论如何,

  compile'c​​om.google.android.gms:play-services-base:6.5.87'

这适用于指南提及的 GCM 类。



但它也可以通过更新到最新的

  compile'c​​om.google.android.gms: play-services-gcm:7.0.0'


Edit: I solved this problem:) Cause of this error :

  1. In the tutorial Implementing GCM Client , there was link to download full source code for demo.
  2. Downloaded for reference , added google_play_service library in build.gradle.
  3. Did some recommended changes like SENDER_ID,SERVER_URL,.. etc
  4. Synch the project with gradle and got this error.

How I solved!

  1. After lot of google I found that this class is not in google_play_service library but it is in gcm.jar which is deprecated now. I dont know why google has given link to old code and explained latest code in the document.
  2. Then I include the gcm.jar
  3. And the error gone, got push notification:)

Hope this will help to someone who got in this trouble!

My Old Question

I am new to android studio. I dont understand build.gradle. Today I was implementing gcm-demo-client following instructions given here https://developer.android.com/google/gcm/client.html But when I import it from suggested open source code I got below errors.

/home/shani/Desktop/gcm-76908409d9d5/samples/gcm-demo-client1/app/src/main/java/com/google/android/gcm/demo/app/GCMIntentService.java:28: error: cannot find symbol
import com.google.android.gcm.GCMBaseIntentService;
                             ^
  symbol:   class GCMBaseIntentService
  location: package com.google.android.gcm

also there are other 25 errors. After some search on Google I found that it is because I had not added google play service library in build.gradle.

Then I added library: Below is my build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.google.android.gcm.demo.app"
        minSdkVersion 8
        targetSdkVersion 16
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        dependencies {
            compile "com.google.android.gms:play-services:3.1.+"
        }
    }
}

Now when I click on sync now link I got Build Success. But when I try to run on real device above error comes. I dont know what I am doing wrong. Please give me the solution, I really spend two days implementing gcm demo app.

解决方案

This happens if you use the latest, 7.0.0 version. They sliced up the Google Play Services a bit further than in 6.5, due to how there is an upper limit to method count (65536).

Anyways,

compile 'com.google.android.gms:play-services-base:6.5.87'

This works with the GCM classes the guides mention.

But it also works by updating to the latest

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

这篇关于无法解析com.google.android.gcm.GCMBaseIntentService; Android工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆