Reputation: 878
Edit: I solved this problem:) Cause of this error :
How I solved!
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.
Upvotes: 3
Views: 17645
Reputation: 82
Use this Google Play Services, it's working
compile 'com.google.android.gms:play-services:8.1.0'
Upvotes: 0
Reputation: 89
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
Upvotes: 3
Reputation: 81549
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'
Upvotes: 4
Reputation: 1385
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.
Upvotes: 0