3 - Add X3M SDK to your app
Download the latest release of XMediator:
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.
Import the package into a project
To add XMediator to your Unity project:
- Make sure your project is open
- Double click the downloaded
.unitypackage
file or go toAssets > Import Package > Custom package...
to import it manually
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
.
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.
Install the following networks
- AppLovin
- Chartboost
- 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.
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.
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:
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:
- Go to
XMediator > Settings
- Mark
Enable GMA properties tag fix
as checked. - Copy the following code snippet into
mainTemplate.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.