问题
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.
回答1:
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'
回答2:
I think your problem is that gradle is not downloading your dependency. I had the same problem but I solved it when I Invalidated cache and restarted android studio. Click on file > invalidate cache/restart
回答3:
The google play services you are using is outdated use the following lines in your gradle file and then again sync the project with gradle.
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
}
This will surely remove your error.
回答4:
Use this Google Play Services, it's working
compile 'com.google.android.gms:play-services:8.1.0'
来源:https://stackoverflow.com/questions/29183240/cannot-resolve-com-google-android-gcm-gcmbaseintentservice-android-studio