3 - Add X3M SDK and MetaMediation adapters 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. - MetaMediation: Set
checked
here.(*) Required to support other mediations
- 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.
Choose Mediators and Networks
Use the Dependencies Generator to generate compatible dependencies for the Networks and Mediation SDKs of your choice, go to XMediator > Mediators Dependency Manager
Install MetaMediation adapters
To install the dependencies click on the Generate Dependencies Button
and accept the warning dialog. This action will generate network dependencies with the latest compatible versions among the selected mediators.
Warning
Any other dependency previously created (e.g. using the Dependency Manager) will be deleted.
In your C# IDE, you can validate the generated MetaMediationDependencies.xml file under the path XMediatiorSettings/Editor
After generating the dependencies , go to the Unity editor and resolve dependencies for Android by clicking on:
Assets -> External Dependency Manager -> Android Resolver -> 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:
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.
It is mandatory to wait for the init callback to complete before making any ad request.