Problem
After upgrading from Google play services 6.5.87 to 7.0.0 I got compile errors in sections of code I hadn't touched.
Symptoms
I got errors similar to these:
- error: package com.google.android.gms.gcm does not exist
import com.google.android.gms.gcm.GoogleCloudMessaging; - error: package GoogleCloudMessaging does not exist
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { - error: cannot find symbol
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
Solution
Simply put: add the GCM API to your gradle file:
Due to Dex limit issues, I stopped importing the full/bulky GooglePlayServices dependency the moment Google made that an option. Instead, I selectively compile the APIs that we need. It seems that version 7.0.0 of Google Play Services is a bit more modular than the previous one and more APIs have have been split out into individual packages.
So to fix this problem, all I had to do was add the new GCM api to my gradle build file. Compile errors went away and both the command-line and IDE builds were happy again!
compile 'com.google.android.gms:play-services-gcm:7.0.0'As an added bonus, the "location" APIs have also been split out. After adding that, I was finally able to get rid of the
play-services-base
dependency that I previously relied on for the GCM & location packages.