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. To simplify the process, the following steps describe two alternative approaches to streamline and improve the integration of your selected networks.

For comparison between these alternatives, see Integrating Mediation Partners.

Step 2 (Alternative 1): Maven & Cocoapods

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

Android

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

9b10e58-gradle_template.png

Declaring the maven dependencies

Copy the required repositories and dependencies, and add them to your corresponding repositories and dependencies blocks to mainTemplate.gradle.

Important

For unity 2019 and above place the dependencies in launcherTemplate.gradle for Unity 2019.

iOS

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

27d8d9c-export_ios.png

  1. Run the following command to install Cocoapods on your system when you do not have it installed on your system:
sudo gem install cocoapods

See Cocoapods Installation for more information.

  1. In the terminal, go to the project main directory and run the following command:
pod init

 

Declaring Cocoapods dependencies

  1. Add the following entries to the generated Podfile by running the following command at the root of the exported project:
pod install --repo-update
  1. From the .workspace file, open the Xcode project.
  2. Click Build and Run.

Important

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

target 'Unity-iPhone' do 
end

Step 2 (Alternative 2): External Dependency Manager for Unity (EDM4U)

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 does the following: 

  • iOS: Adds the respective entries to your Podfile.
  • Android: Adds the respective entries to  mainTemplate.gradle .
    The EDM4U will download the raw dependencies and include them in the project under the correct folder when you do not have mainTemplate.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.

8e2aba9-pack_manager.png

For information about EDM4U, see External Dependency Manager for Unity.

Declaring Mediated Network Dependencies with EDM4U

  1. Open and save a new .xml file in a folder named Editor.
    The filename may be any valid name, but conclude with Dependencies.xml, for example, FairBidMediationDependencies.xml.
  2. Save the file in the Editor folder and insert the required content.

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

Resolving Dependencies on iOS

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 (Info.plist and Android Manifest)

Android

Android Manifest

Some networks might require you to add entries to the AndroidManifest.xml when you build for Android. If you have selected one of those networks in the table, the respective entries appears:

  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>.
  3. Create an AndroidManifest.xml file  in Assets → Plugins → Android when your project does not contain an AndroidManifest.xml.

An example of a typical Unity Manifest follows.

<?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 21. Enable multidex to solve the problem and add the following snippet to your mainTemplate.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.

iOS

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.

d8fa7fb-plist.png

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 ⇧