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 page provides 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:
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 found here.
In the terminal navigate to the project main directory and run:
pod init
Declaring the cocoapods dependencies
Add 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.
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 a mainTemplate.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 want to use a different version and not the last one, you can browse it here.
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 will happen 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
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
When building for iOS, depending on the selected networks, you might need to add entries to your Info.plist file. If that is the case, include the following:
You can use Xcode’s GUI to edit it:
or open the .plist file with a text editor and copy paste the snippet above.
iOS plist