Unity Mediation Table

Unity is a cross-platform engine with an editor available on Windows, macOS, and Linux, which supports game development for many platforms, including mobile devices. Integrating ad networks into your Unity project involves adding specific libraries or dependencies for iOS and Android platforms, including iOS frameworks and Android archives (.aar ). Properly managing these dependencies ensures your app's ad networks function effectively.

Unity's official solution requires you to manually place native archives into specific project folders, which can be cumbersome and prone to errors. There are two alternative approaches to streamline and improve the integration of your selected networks, as outlined in the table below.

Maven and CocoaPods

With Maven and CocoaPods, you use the Gradle template for Android that Unity has provided since 2017 to declare dependencies, as you would do natively. On iOS, you edit a CocoaPod file for the exported Xcode project to add your required network SDKs, run pod install, and then build your iOS project.

PROS CONS
  • The Gradle file can take care of the method count issue.
  • Transitive dependencies are resolved automatically.
  • Gradle resolves conflicts in transitive dependencies unless major issues arise.
  • You can maintain your network SDK dependencies in a Gradle and CocoaPod file.
  • Updating a network SDK is diminished to updating a line in the build file.
  • It works seamlessly in a CI environment.
  • You have the flexibility to update network SDK versions for Android or iOS independently.
  • Manifest declarations on Android for networks that require them must be addressed separately.
  • This approach can lead to conflicts when used simultaneously with local jars/aars.
  • On iOS, you must manually run the command pod install after exporting the XCode project.

External Dependency Manager

The External Dependency Manager for Unity (EDM4U) (previously known as the "Unity Jar Resolver") is a version management tool for Unity that can manage Android and iOS dependencies and resolve transitive dependencies. You must include the EDM4U in your Unity project and then declare the network dependencies in an XML file.

PROS CONS
  • You can maintain your network SDK dependencies in a single XML file for Android and iOS.
  • You have the flexibility to update network SDK versions for Android and iOS independently.
  • It is very likely that the method count on Android can become a problem when integrating more than a certain number of networks—this must be solved separately.
  • The EDM4U sometimes adds many more dependencies than necessary to make the build work. This makes the project heavier, and the method count issue is more likely to happen on Android.
  • The EDM4U has a specific way to resolve conflicting dependencies on Android. It may "loosen" the version of a declared network SDK with conflicting dependencies, resulting in unwanted versions being integrated. Click here for more information. This requires manual steps for the problematic network SDKs.
  • The tool sometimes does not resolve the dependencies properly and can create conflicts within the imported packages. This must be solved by inspecting the error output.
  • Manifest declarations on Android for networks that require them must be addressed separately.
  • This approach can lead to conflicts when used simultaneously with local jars/aars.
  • On iOS, you must manually run the command “pod install” after exporting the XCode project.

Step 2 (Alternative 1): Adding Dependencies using Maven and CocoaPods

Integrating Maven and CocoaPods requires minimal setup and involves steps similar to native projects. Specify the dependencies in configuration files and allow the native dependency management tools to resolve them.

For Android

Declaring and Setting up Maven Dependencies

  1. Open the Player Settings, and select the Custom Gradle Template checkbox, which generates a file in Assets/Plugins/Android/launcherTemplate.gradle.

9b10e58-gradle_template.png

  1. Copy the required repositories and dependencies, and add them to your corresponding repositories and dependencies blocks in launcherTemplate.gradle.

 

For iOS

Declaring and Setting up CocoaPods Dependencies

  1. Export the Xcode project and build the project on Unity.

27d8d9c-export_ios.png

  1. If CocoaPods is not installed on your system, install it by running the following command in the terminal:
sudo gem install cocoapods

See CocoaPods Installation for more information.

  1. Navigate to the project's main directory in the terminal and run the following command to initialize CocoaPods:
pod init
  1. Add the following entries to the generated Podfile by running the following command:
pod install --repo-update
  1. Open the .workspace file in Xcode.
  2. Click Build and Run to complete the setup.

Note

Add the Unity-iPhone target to the podfile when you use hyprMX.

target 'Unity-iPhone' do 
end

 

Step 2 (Alternative 2): Adding Dependencies with EDM4U

External Dependency Manager for Unity (EDM4U), previously known as Unity Jar Resolver, is an open-source tool for managing native dependencies and offers advantages for projects that already use EDM4U for dependency management or seek to avoid direct interaction with CocoaPods.

EDM4U automatically resolves all the dependencies declared in a specific .xml file and adds the respective entries to  launcherTemplate.gradle. The EDM4U will download the raw dependencies and include them in the project under the correct folder when you do not have launcherTemplate.gradle.

Downloading and Importing Mediated Network Dependencies with EDM4U

  1. Click Declaring Mediated Network Dependencies with EDM4U if you use EDM4U.
  2. Download and import the latest version of EDM4U. 
    The following dialogue box appears when you use Unity 2018 and above.

de834df-edm4u_import.png

  1. Select Add Selected Registries.
    The following dialogue box appears.

b23f838-add_registries.png

  1. Click Apply to move all the EDM4U resources from /Assets to /Packages, which 
    makes it easier to maintain, update, downgrade, or remove with the Unity Package Manager GUI.

For Android

Resolving Dependencies on Android

Dependencies resolve automatically for Android.
(Optional) To force dependency resolution, from the Menu bar, navigate to Assets → External Dependency Manager → Android Resolver → Force Resolve.

59a452c-force_resolve.png

 

For iOS

Resolving Dependencies on iOS

EDM4U automatically resolves all the dependencies declared in a specific .xml file and add the respective entries to your Podfile.

In iOS, resolution occurs when you export the project. Do the following when you select AdMob, hyprMX, or EDM:

  • AdMob: Click build as you need to Add SKAdNetwork IDs to the Info.plist.
  • HyprMX
    1. Navigate to Assests → External Dependency Manager → iOS Resolver  → Settings.
    2. Select Always add the main target to Podfile.
  • EDM
    1. Navigate to Assets → External Dependency Manager → iOS Resolver  → Settings.
    2. Deselect Link frameworks statically.
      If you do not deselect the option, you may encounter a compilation error about missing the   FairBidSDK/FairBidSDK-Swift.h file. 
    3. Open the .xcworkspace file in Xcode, not the .xcodeproj file.
      EDM creates the .xcworkspace file when it builds the project.
    4. Locate the Podfile in the build folder and run pod install when the .xcworkspace file does not appear to generate .xcworkspace.

 

Step 3: Final Configurations

Configure the  AndroidManifest.xml file and Info.plist file to ensure your application operates correctly across both Android and iOS platforms. These configurations are essential for integrating required services, ensuring compatibility with various network functionalities and enabling precise tracking through SKAdNetwork IDs.

 

For Android

Configuring the Android Manifest

Some networks might require you to add entries to AndroidManifest.xml when you build for Android. Create an AndroidManifest.xml file  in Assets → Plugins → Android when your project does not contain an AndroidManifest.xml. If you have selected one of those networks in the table, the respective entries appear:

  1. Copy the entries to the AndroidManifest.xml.
  2. Paste the relevant entries in the root level under <manifest> and the remaining ones under <application>.

The following example shows a typical Unity Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="preferExternal">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application
        android:theme="@style/UnityThemeSelector"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name">
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>

For most Unity installations, the default manifest is available in the Editor's installation at the following location: /Applications → Unity → Hub → Editor → [version] → PlaybackEngines → AndroidPlayer → Apk

For further information about integrating and controlling an Android manifest in your Unity integration, see Utility Android App Manifest.

Dex limit

An Android limitation prevents you from having more than 65536 methods when you package your app plus dependencies. A limitation typically occurs when your app targets versions lower than Android API 21. Enable multidex to solve the problem, and add the following snippet to your launcherTemplate.gradle file. 

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
}

For further information, see Enable multidex for apps with over 64K methods.

 

For iOS

Configuring the Info.plist and Adding SKAdNetwork IDs

DT helps you and generates an exhaustive list of the required SKAdNetwork IDs to implement in your Info.plist file. The list includes the SKAdNetwork IDs of the DT Exchange DSPs and any check-boxed mediated networks in Step 1.

Add the list to the app Info.plist file when you select your mediated network set.

Important

The SKAdNetwork ID list is dynamic and might have changed when you deploy your application to production. We highly recommend integrating our SKAdNetwork ID Auto Updater Tool into your build process to ensure the list is always as up-to-date.

The Info.plistfile is located in the .workplace project Unity and exports to the folder named after your app.

You can use Xcode's GUI to edit it or open the .plist file with a text editor, copy and paste the snippet.

Back to Top ⇧