Use a secondary Firebase project for FCM

Configure a non-default Firebase project for Firebase Cloud Messaging in the Airship SDK, for apps that make use of multiple Firebase projects.

By default, the Airship SDK will use the data in google-services.json to configure Firebase Messaging. If your app makes use of multiple Firebase projects, you can instruct the Airship SDK to use a specific named Firebase project for Firebase Cloud Messaging (FCM) by completing the following steps.

Initialize a named Firebase application

In order to create a secondary Firebase application instance, you’ll need to manually configure FirebaseOptions and initialize your secondary Firebase application.

 Note

The Firebase application should be initialized before takeOff, or during the onAirshipReady callback.

Initialize the secondary Firebase Application instance
// Manually configure FirebaseOptions for the secondary Firebase Application.
FirebaseOptions options = new FirebaseOptions.Builder()
        .setProjectId("Your Firebase Project ID")
        .setApplicationId("Your Firebase Application ID")
        .setApiKey("Your Firebase API key")
        .setGcmSenderId("Your GCM Sender ID")
        .build();

// Initialize the secondary Firebase Application.
FirebaseApp.initializeApp(context, options, "secondary");
// Manually configure FirebaseOptions for the secondary Firebase Application.
val options = FirebaseOptions.Builder()
        .setProjectId("Your Firebase Project ID")
        .setApplicationId("Your Firebase Application ID")
        .setApiKey("Your Firebase API key")
        .setGcmSenderId("Your GCM Sender ID")
        .build()

// Initialize the secondary Firebase Application.
Firebase.initialize(context, options, "secondary")

Configure the Airship SDK to use the named Firebase application

Now that you have initialized your secondary Firebase application, you can configure the Airship SDK to use it by setting the fcmFirebaseAppName key in your airshipconfig.properties file.

Example airshipconfig.properties
developmentAppKey = Your Development App Key
developmentAppSecret = Your Development App Secret

productionAppKey = Your Production App Key
productionAppSecret = Your Production Secret

# ...

# Set the Firebase application used for FCM
fcmFirebaseAppName = "secondary"

Alternately, the secondary Firebase application can configured using the fcmFirebaseAppName() method on AirshipConfig.Builder.