Skip to content

3 - Add X3M SDK to your app

Download the latest release of XMediator:

XMediator_latest.unitypackage

Enable Gradle Templates

For a cleaner dependency management experience, enable Gradle Templates for Android builds inside the Unity Editor if you haven't already. This will avoid bloating your Assets folder with the native libs each ad adapter requires.

To do this go to File > Build Settings... > Player Settings... > Android > Publishing Settings > Build and make sure Custom Main Gradle Template is checked.

Android Player Settings

Import the package into a project

To add XMediator to your Unity project:

  1. Make sure your project is open
  2. Double click the downloaded .unitypackage file or go to Assets > Import Package > Custom package... to import it manually

Unity Package Import

Unity will load the package and then show a confirmation dialog displaying the files to be added after the import. Click Import to finish importing the assets.

Configure settings

Use the settings window to configure your integration tokens, Google Ads AppId, and target build options. To begin, go to XMediator > Settings.

XMediator Dependency Manager

XMediator Settings

Here you can configure the following items:

  • Publisher: Required to resolve custom publisher dependencies. Set default here.
  • Android Maven Repository Token: Set turnkey-1e81749db375de151ff2b6c9e1774390 here (*)
  • Dependency Manager Token: Set 010ef81f6d8ac6f9555b79b4f40f9c9f here (*)
  • Disable GoogleAds Android AppId: Check to avoid automatically appending the GoogleAds AppId meta element to the Android manifest. Set unchecked here.
  • GoogleAds Android AppId: Set the Google Application ID obtained in the step 2.
  • GoogleAds iOS AppId: Set the Google Application ID obtained in the step 2.
  • Skip Swift Configuration: Set unchecked here.
  • Skip SkAdNetwork Ids Configuration: Set unchecked here.
  • Enable GMA properties tag fix: See Optional: Enable GMA workaround for projects with Unity 2021 and lower

    (*) Required to access our repositories, in next release the repositories will be public.

Install adapters

To integrate additional mediation network adapters go to XMediator > Dependency Manager, where you will see a list of the adapters available for installation, as well as the current version of XMediator.

XMediator Menu

XMediator Dependency Manager

Install the following networks

  • AppLovin
  • Chartboost
  • Facebook
  • Fairbid
  • Fyber
  • GoogleAds
  • InMobi
  • IronSource
  • Mintegral
  • Pangle
  • Stack
  • UnityAds
  • Vungle
  • XMediator

It also performs a validation of adapter version compatibility with Core (or other adapters). If you encounter the message below after a version change, you must match the required version. See the changelog documentation for more information.

Non compliant dependency

After the installation completes, remember to run EDM4U's Dependency Resolver by going to Assets > External Dependency Manager > Android Resolver > Force Resolve to update the Gradle Templates. This will make sure all dependencies get correctly added into your final Android build. For more information check out Google's EDM4U official repository.

Force Resolve

Optional: Enable GMA workaround for projects with Unity 2021 and lower

When integrating the Google Ads adapter in projects with Unity 2021 or lower you might get the following error on Android builds:

AAPT: error: unexpected element <property> found in <manifest><application>.

This error occurs due to a new property introduced on GMA SDK 22.5.0 that is not supported on older AGP versions. To fix this, you can enable the GMA workaround to remove the new property:

  1. Go to XMediator > Settings
  2. Mark Enable GMA properties tag fix as checked.
  3. Copy the following code snippet into mainTemplate.gradle:
    gradle.projectsEvaluated {
        apply from: 'XMediatorPlugin.androidlib/validate_dependencies.gradle'
    }
    

Initialize the SDK

Before requesting any ad, make sure to call XMediatorAds.StartWith(). This method configures your Application Key, and fetches the required configuration parameters for the ad placements in your app, among other things.

Additionally, you may want to wait for the initialization callback to complete. This will ensure that your placement' requests have the necessary prebid configurations.

XMediatorAds.StartWith(
    appKey: "<your-app-key>",
    initSettings: new InitSettings(
        userProperties: new UserProperties(
            userId: "<your-user-id>"
        )
    ),
    initCallback: result => 
    {
        Debug.Log("Initialization complete! You can start loading your placements!")
    }
);

Warning

To ensure the SDK is correctly configured before ad mediation begins, any method that performs an ad request will raise an exception if they are called before XMediatorAds.StartWith() is invoked.

But since this initial configuration will happen synchronously, it is not mandatory to wait for the init callback to complete before making any ad request, just making sure this method is called before requesting any ad will suffice; you may even request an ad in the subsequent instruction right after StartWith is called.