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.