> ## Documentation Index
> Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Migration And Precedence

### Android Migration Steps

To migrate from manual code-based initialization to the XML file-based approach, follow the below 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.

<CodeGroup>
  ```javascript Java theme={null}
  import com.moengage.capacitor.MoEInitializer;

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

  ```kotlin Kotlin theme={null}
  import com.moengage.capacitor.MoEInitializer

  override fun onCreate() {
      super.onCreate()
      // ... existing code
      MoEInitializer.initialiseDefaultInstance(this)
  }
  ```
</CodeGroup>

### 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 (e.g., WorkspaceId, DataCenter) inside the *MoEngage* key in 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.

<CodeGroup>
  ```Swift Swift wrap theme={null}
  import MoEngageSDK

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

  ```objective-c objective-c wrap theme={null}
  #import <MoEngageSDK/MoEngageSDK.h>
  import CapacitorMoengageCore
  	- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
    // ... existing code
    [[MoECapacitorInitializer sharedInstance] intializeDefaultInstanceWithAdditionalConfig:[[MoEngageSDKDefaultInitializationConfig alloc] init]];
    return true
  }
  ```
</CodeGroup>

### 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.
