Migrate your app to Firebase Cloud Messaging

Our Android SDK (1.3.3 and above) supports Firebase Cloud Messaging, the new Google Cloud Messaging. 

You can continue to use GCM - Google will continue to support it, as will we, for the time being - but all new features from Google will only be added to Firebase, and all new Android apps must use FCM (See Google's FAQs for Cloud Messaging).

So, it's probably a good idea to migrate your app over to Firebase. 

Import your GCM project into Firebase

The first step is to migrate your existing Android app to FCM using Google's Firebase Console:

  1. In the Firebase console, select Import Google Project.

  2. Select your GCM project from the list of existing projects and select Add Firebase.
  3. In the Firebase welcome screen, select Add Firebase to your Android App.
  4. Provide your package name and SHA-1, and select Add App. A new google-services.json file for your Firebase app is downloaded.

  5. Select Continue and follow the detailed instructions for adding the Google Services plugin in Android Studio.

Add the Google JSON file to your app/ folder

Be sure to copy the file created in the steps above to your project's module folder, which is typically app/.

Update your project-level build.gradle

buildscript {
    dependencies {
        // For Firebase
        classpath 'com.google.gms:google-services:3.0.0'

Update your app-level build.gradle

Replace the GCM dependency with FCM. And apply the google-services plugin.

dependencies {
  // remove this line...
  // compile 'com.google.android.gms:play-services-gcm:9.0.0+'

  // Replace it with these. Be sure you have versions 10.0.1 of play services.
  compile 'com.google.firebase:firebase-messaging:10.0.1'
  compile 'com.google.android.gms:play-services-location:10.0.1'
apply plugin: 'com.google.gms.google-services'

Update your app's manifest

You can remove the GCM receivers and services from your manifest, since FCM will add the correct receiver automatically.

<!-- This is no longer needed -->
    android:permission="com.google.android.c2dm.permission.SEND" >
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="[YOUR_PACKAGE_NAME]" />

<!-- The next two services are not needed for Firebase -->
    android:exported="false" >
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
       <action android:name="com.google.android.gms.iid.InstanceID" />

Our Android SDK versions 2.1.0+ support manifest merging, so your manifest can be as simple as this:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="[com.YOUR_PACKAGE]"
xmlns:tools="http://schemas.android.com/tools" >

        tools:overrideLibrary="com.leanplum, com.google.android.gms"/>

    <!-- These permissions are required only for push notifications. -->

    <!-- Optional. Prevents the device from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <!-- These permissions are required only for geofencing. -->

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>   
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        android:name=".[YOUR_APPLICATION_CLASS]" >
               android:value="@integer/google_play_services_version" />

You can view the services and permissions our SDK adds to your manifest during the merge in our source code here. If you choose to use an older version of our SDK, or install our SDK using the JAR file, you'll need to manage the manifest yourself. See an example of a manifest.

Update your application class

With Firebase, you do not need to set a Sender Id. So you should update your Application class as follows:

public class ApplicationClass extends Application {

  // Remove this line
  // LeanplumPushService.setGcmSenderId(LeanplumPushService.LEANPLUM_SENDER_ID);


Add your FCM Server Key to Leanplum

In the Firebase console, click the gear icon next to Overview, then click Project Settings.

In your project's settings, go to the Cloud Messaging tab. In this section of your settings, you will see your Server key. Copy the key.

In the Leanplum dashboard, in your App Settings click Keys & Settings. Go to the Push Notifications tab and enter/paste your key into the Google API key field.


Note: Not all Android Virtual Devices (AVDs) support Firebase. This level of support does not always match the SDK support (i.e. you can be running a supported SDK, but the AVD will not be able to receive push notifications). If you plan to test Firebase on an Android Studio emulator, be sure to review Google's list of supported AVDs for Firebase.

Other documentation

For more complex app setups, and other documentation, you may want to refer to Google's FCM migration guide

Was this article helpful?
Have more questions? Submit a request