Android

Configuring Build Settings

Add Maven Repository

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

Groovy
buildscript {
    repositories {
    mavenCentral()
    }
  }
    allprojects {
    	repositories {
      	mavenCentral()
      }
}

Enable Java 8

The SDK is target and source compatible with version 8 of the Java Programming Language. Enable Java 8 in the application build.gradle if not done already.

build.gradle
android {
  ...
  compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
  }
  kotlinOptions {
  jvmTarget = '1.8'
  }
}

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')

Adding MoEngage Dependency

Add the following dependency in the android/app/build.gradle file.

build.gradle
dependencies {
    ...
    implementation("com.moengage:moe-android-sdk:$sdkVersion")
}

replace $sdkVersion with the appropriate SDK version

For more information about the build config and other libraries used by the MoEngage Android SDK, refer to the SDK Configuration.

Add Androidx Libraries

The SDK depends on a few Androidx libraries for its functioning, add the below Androidx libraries in your application if not done already.

Groovy
implementation("androidx.core:core:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("androidx.lifecycle:lifecycle-process:2.4.0")

The MoEngage SDK depends on the lifecycle-process library for a few key features to work and the latest version of lifecycle-process depends on the androidx.startup:startup-runtime library. Hence do not remove the InitializationProvider component from the manifest. When adding other Initializers using the startup-runtime make sure the Initializer for lifecycle-process library is also added. Refer to the documentation to know how to add the Initializer.

Add the MoEngage React Package to 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 to your java file.

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

Previous

Next

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

How can we improve this article?