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

> Migrate your MoEngage Flutter SDK from code-based initialization to file-based configuration.

### Android Migration Steps

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

1. **Add Configuration File:** Place the `moengage_config` file in the (`src/main/assets/moengage.xml`) path.
2. **Update Application Class:** Remove the existing initialization code (the manual `MoEngage.Builder` logic) from your Application class and replace it with the default instance initialization to enable reading from the XML file.

| Code Language | Existing Code                                                                                                                                                                                              | Replace with                                                          |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| Kotlin        | <code>val moEngage: MoEngage.Builder = MoEngage.Builder(this,"YOUR\_Workspace\_ID", DataCenter.DATA\_CENTER\_X) <br /> MoEInitializer.initialiseDefaultInstance(context = this, builder = moEngage)</code> | <code>MoEInitializer.initializeDefaultInstance(application) </code>   |
| Java          | <code>MoEngage.Builder moEngage = new MoEngage.Builder(this, "YOUR\_Workspace\_ID", YOUR\_DATA\_CENTER); MoEInitializer.initialiseDefaultInstance(this, moEngage); </code>                                 | <code>MoEInitializer.INSTANCE.initializeDefaultInstance(this);</code> |

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

| Code Language | Existing Code                                                                                                            | Replace with                                                                    |
| ------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
| Swift         | <code>MoEngageInitializer.sharedInstance.initializeDefaultInstance(sdkConfig, launchOptions: launchOptions)   </code>    | <code> MoEngageInitializer.sharedInstance.initializeDefaultInstance()   </code> |
| Objective-C   | <code>\[\[MoEngageInitializer sharedInstance] initializeDefaultInstance:sdkConfig launchOptions:launchOptions];  </code> | <code>\[MoEngageInitializer.sharedInstance initializeDefaultInstance]; </code>  |

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