Migration and Precedence

Android Migration Steps

To migrate from manual code-based initialization to the XML file-based approach, follow these steps:

  1. Add configuration file :Add your generated moengage.xml (or any .xml under res/values/ with the correct com_moengage_ resource entries) to the app module, in the android/app/src/main/res/values/moengage.xml path.
  2. Update the Application class : In android/app/src/main/java/<your/_package>/MainApplication.java (or .kt), remove the MoEngage.Builder setup and call file-based initialization instead.
Java Kotlin
import com.moengage.capacitor.MoEInitializer;

@Override
public void onCreate() {
    super.onCreate();
    // ... existing code
    MoEInitializer.initialiseDefaultInstance(this);
}

iOS Migration Steps

To migrate from code-based initialization to the Info.plist based approach, follow these steps:

  1. Update Info.plist: Add the required MoEngage configuration keys (for example, WorkspaceId, DataCenter, etc.) directly to your Info.plist file.
  2. Update AppDelegate: Remove the existing initialization code (the manual MoEngageSDKConfig logic) from your AppDelegate class and replace it with the default instance initialization to enable reading from the Info.plist file.
Swift Objective-c
import MoEngageSDK

	override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) - Bool {
  // ... existing code
  MoECapacitorInitializer.sharedInstance.intializeDefaultInstance()
  return true 
}

Precedence Rules

The source of configuration is determined by the initialization function called in your native code:

  • Android:
    • File-Based Init: Calling MoEInitializer.initializeDefaultInstance(context) instructs the SDK to look for and read the moengage.xml file.
    • Code-Based Init: Calling MoEInitializer.initialize(context, moEngage.Builder) will initialize the SDK using the configuration object passed in the parameters, ignoring the XML file even if it exists.
  • iOS: Auto-initialization (via Info.plist) occurs first. However, if you subsequently call the manual initialize method with a configuration object in your code, it will update the current instance configuration.

Previous

Next

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

How can we improve this article?