Configure the React Native Plugin for Android Apps

After you install and configure the MobilePush SDK React Native plugin, configure the plugin to enable push support for the Android platform.

Prerequisites 

Before you configure the MobilePush SDK React Native plugin for Android apps, make sure that the plugin is installed and configured for your app. See Marketing Cloud React Native Plugin.

Add the MobilePush SDK for Android Repository 

Add the MobilePush SDK for Android repository to your build.gradle file.

build.gradle
1allprojects {
2  repositories {
3    maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
4    //... Other repos
5  }
6}

Provide FCM Credentials 

To enable push support for Android, provide your FCM credentials by placing the google-services.json file in the android/app directory.

  1. Download the google-services.json file from your app’s Firebase console and place it in your project’s android/app directory.

  2. Include the Google Services plugin in your android/build.gradle file.

    build.gradle
    1buildscript {
    2  repositories {
    3    google() // Google’s Maven repository
    4  }
    5
    6  dependencies {
    7    // ...
    8    // Add this line:
    9    classpath 'com.google.gms:google-services:4.3.15'
    10  }
    11}
  3. Add the plugin to your build.gradle file.

    build.gradle
    1// Add the google services plugin to your build.gradle file
    2apply plugin: 'com.google.gms.google-services'

Configure the SDK 

Configure the SDK in your MainApplication.java class as shown in this example

MainApplication.java
1@Override
2public void onCreate() {
3  super.onCreate();
4
5  SFMCSdk.configure((Context) this, SFMCSdkModuleConfig.build(builder -> {
6      builder.setPushModuleConfig(MarketingCloudConfig.builder()
7              .setApplicationId("{MC_APP_ID}")
8              .setAccessToken("{MC_ACCESS_TOKEN}")
9              .setSenderId("{FCM_SENDER_ID_FOR_MC_APP}")
10              .setMarketingCloudServerUrl("{MC_APP_SERVER_URL}")
11              .setNotificationCustomizationOptions(NotificationCustomizationOptions.create(R.drawable.ic_notification))
12              .setAnalyticsEnabled(true)
13              .build(this));
14
15      return null;
16  }), initializationStatus -> {
17      Log.e("TAG", "STATUS "+initializationStatus);
18      if (initializationStatus.getStatus() == 1) {
19          Log.e("TAG", "STATUS SUCCESS");
20      }
21      return null;
22  });
23
24    // ... The rest of the onCreate method
25}

To customize push notification functionality for Android apps, see the notification customization guide.

To implement the Carousel and Button actions features introduced in Android SDK version 9.0.0, refer to the Configure Button and Carousel Actions section.