无法解析com.google.android.gcm.GCMBaseIntentService; Android工作室 [英] Cannot resolve com.google.android.gcm.GCMBaseIntentService; Android studio
问题描述
$ b
我如何解决问题!
- 经过很多google之后,我发现这个类不在google_play_service库中,但它在gcm.jar中,现在不推荐使用。
我不知道为什么google给出了旧代码的链接,并解释了文档中的最新代码。
- 然后我包含gcm.jar
- 错误消失了,得到了推送通知:)
希望这会对遇到麻烦的人有所帮助!
> 我的老问题
我是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'com.google.android.gms:play-services-base:6.5.87'
这适用于指南提及的 GCM
类。
但它也可以通过更新到最新的
compile'com.google.android.gms: play-services-gcm:7.0.0'
Edit: I solved this problem:) Cause of this error :
- In the tutorial Implementing GCM Client , there was link to download full source code for demo.
- Downloaded for reference , added google_play_service library in build.gradle.
- Did some recommended changes like SENDER_ID,SERVER_URL,.. etc
- Synch the project with gradle and got this error.
How I solved!
- 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.
- Then I include the gcm.jar
- 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屋!