SDK Installation

Install MoEngage's React Native plugin using the npm package manager. And then link your native dependencies :

Shell
$ npm install react-native-moengage
$ react-native link react-native-moengage

After installing the plugin let us move on to platform-specific configuration.

Android

MavenBadge

Add mavenCentral() repository in the project-level build.gradle file.

build.gradle
buildscript {
    repositories {
        mavenCentral()
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

In android/settings.gradle add the following

Groovy
include ':react-native-moengage'
project(':react-native-moengage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-moengage/android')

In android/app/build.gradle add the following

Groovy
dependencies {
    ...
      
    implementation project(':react-native-moengage')
    implementation("com.moengage:moe-android-sdk:$sdkVersion")
    implementation("androidx.core:core:1.3.1")
    implementation("androidx.appcompat:appcompat:1.2.0")
    implementation("androidx.lifecycle:lifecycle-process:2.2.0")
}

where $sdkVersion should be replaced by the latest version of the MoEngage SDK.
Add the MoEngage React Package in the Application class's getPackages()

Java
public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(), new MoEReactPackage());
    }
  };

  @Override public void onCreate() {
    super.onCreate();
  }

  @Override
  public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
  }
}

In case you are facing issues with the import add the below import statement in your java file.

Java
import com.moengage.react.MoEReactPackage;
import com.moengage.core.MoEngage;

iOS

 

Native SDK Version:

The current react-native-moengage plugin supports MoEngage-iOS-SDK version 7.*.

 

The below steps are only required for react-native-moengage plugin version below 6.0.0. If using plugin version 6.0.0, proceed to SDK Initialization.

CocoaPods Integration [Required for version < 6.0.0]:

  • CocoaPods Integration is supported from react-native-moengage version 4.0.0

Run pod install to add our react native plugin and MoEngage-iOS-SDK pods to the iOS project. Post that add "${PODS_ROOT}/../<YourProjectName>" to the Header Search Path of ReactNativeMoEngage target in Pods project as shown below:

655cfc5-Screenshot_2019-07-26_at_22.31.02.png

Libraries Integration [Required for version < 6.0.0]:

In case if you are using the Libraries Integration, you will have to explicitly update pod file to install our native MoEngage iOS SDK. Add MoEngage-iOS-SDK to your pod file:

Ruby
pod 'MoEngage-iOS-SDK'

After installing the Pods, select the MoEReactBridge target in MoEReactBridge.xcodeproj and go to Header Search Paths section in Build Settings as shown below. Here update the search path $(SRCROOT)/../../../ios to include your Project's main directory which contains the AppDelegate file as shown below.

b2c901b-Screenshot_2019-08-23_at_23.37.29.png

 
  • Updating the Header Search Path is important as the MoEngage React Native plugin needs access to the AppDelegate file of your project.
  • In case if you get errors in the test targets of the project, go to build settings of the test target and add -lc++ flag to Other Linker Flags as shown below :

a23a210-Screen_Shot_2016-11-30_at_19.38.48.png

SDK is successfully installed in the project, and ready to use.

For more information about samples, refer to React Native Samples.

Was this article helpful?
0 out of 0 found this helpful