These mediated networks are essentially native dependencies (iOS frameworks and Android archives - .aar).
Unity's official solution to integrate this type of dependencies involves manual manipulation of these native archives into specific folders.
Often this leads to a cumbersome and error prone process.
The sections below provide instructions on how to integrate the networks you have selected following 2 different approaches/tools we believe can make this process as frictionless and as reliable as possible:
(This pageprovides an in-depth comparison between these alternatives).
Step 2 (alternative 1): Maven & Cocoapods
This kind of integration requires having a minimum set up and then following some steps in the same way you would do it for a native project, that is, adding your dependencies as text in a file and letting native dependency management tools resolve them.
Android
Open the Player Settings and enable the option "Custom Gradle Template":
A file under Assets/Plugins/Android/mainTemplate.gradle will be created.
Declaring the maven dependencies
Grab the following repositories and dependencies, and add them to your corresponding repositories and dependencies blocks inside that file:
Unity 2019 and above
Remember to place the dependencies inside your launcherTemplate.gradle
.
iOS
Export the Xcode project by building on Unity:
If you don't have Cocoapods installed in your system, you can achieve it by running the following command:
sudo gem install cocoapods
More details about Cocoapods installation can be foundhere.
In the terminal navigate to the project main directory and run:
pod init
Declaring the cocoapods dependencies
Add the following entries to the generated Podfile:
pod install --repo-update
at the root of the exported project.
Open the Xcode project by opening the .workspace file.
You can now build and run.
Important
If you are using hyprMX, ensure that you are adding the 'Unity-iPhone' target to your podfile (it can be left empty).
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 which handles native dependencies for you.
This can be useful if you are already using EDM4U to include other dependencies in your project or if you don't want to deal with Cocoapods directly.
The EDM4U automatically resolves all the dependencies declared in a specific xml file.
When building for iOS, it adds the respective entries to your Podfile
When building for Android, it adds the respective entries to your mainTemplate.gradle
(In case you don't have amainTemplate.gradle, the EDM4U will directly download the raw dependencies and include them into your project under the correct folder.)
Download and Import EDM4U
If you are already using EDM4U skip to Declare mediated networks dependencies with EDM4U
Download and import the latest version of EDM4U from this link.
If you are using Unity 2018 or above, you will be prompted with the following dialogue:
If you choose to select “Add Selected Registries” you’ll get a follow up dialogue:
Clicking “Apply” will move all the EDM4U resources from /Assets to /Packages making it easier for you to maintain this package (update/downgrade/remove) using Unity’s Package Manager GUI:.
More information about EDM4U can be found inside its main page here.
Declare mediated networks dependencies with EDM4U
- Create a new xml file. The filename can be anything you want, as long as it ends with Dependencies.xml (e.g.: FairBidMediationDependencies.xml.)
- This File needs to be under a folder named Editor
- Copy the following content to that file
You can always force the dependency resolution by clicking on the menu Assets > External Dependency Manager > Android Resolver > Force Resolve.
On iOS, the resolution occurs when exporting the project.
Important
- If you have AdMob selected, you should build your project (instead of Build And Run) since you’ll need to add some information to your Info.plist. See iOS Info.plist section below
- If you have hyprMX selected, do the following:
- Go to assets >> External Dependency Manager >> iOS Resolver >> Settings
- Select "Always add the main target to Podfile"
Step 3: Final Configurations (Info.plist and Android manifest)
Android
When building for Android, some networks might require adding entries in the AndroidManifest.xml.
If you have selected one of those networks in the table, the respective entries will show below:
Make sure you pasting the entries that should go under the root level (permissions) directly under <manifest and the remaining ones under <application
In case your project does not have AndroidManifest.xml yet, you can simply create one and put it under Assets/Plugins/Android.
This is a typical Manifest ready to work on Unity:
<?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, you can find this default manifest under the Editor’s installation: /Applications/Unity/(Hub)/Editor/[version]/PlaybackEngines/AndroidPlayer/Apk
You can follow Unity’s official instructions to learn more about how to integrate/take control of an Android manifest in your unity integration here.
There is an android limitation that prevents you from having more than 65536 methods when packaging your app plus dependencies. This problem typically arises when your app targets versions lower than 21.
However, this problem can be overcome by enabling multidex, adding the following snippet into your mainTemplate.gradle file:
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
More information can be found here.
iOS
DT helps you to conveniently generate an exhaustive list of your required SKAdNetwork IDs to implement in your app info.plist file.
The following list includes the SKAdNetwork IDs of the DT Exchange DSPs and of any of the check boxed mediated networks in the Step 1 table above.
After choosing your set of mediated networks, add this list to your app’s info.plist file.
Important
This list is dynamic and it might have changed by the time you are deploying your application to production. To make sure you have this list always as up to date as possible, we highly recommend you integrate our SKAdNetwork ID Auto Updater Tool as part of your build process.
You can use Xcode’s GUI to edit it:
or open the .plist file with a text editor and copy paste the snippet above.