Integrate the MoPub SDK for Unity
- High-Level Steps to Integrate
- Step 1. Integrate the Plugin and Mediation Adapters
- Step 2. Initialize the SDK
- Step 3. Configure Ad Units in Your App
- Rate Limiting
- Note About Unity Build Systems
- About the Jar Resolver
Use these instructions to integrate the MoPub SDK with your Unity app. If you have already integrated our Unity plugin and are upgrading to a higher version, follow our migrating instructions.
High-Level Steps to Integrate
MoPub supports Unity editor version 5.5 and above
- Integrate the MoPub Unity plugin and mediation adapters.
- Initialize the SDK.
- Configure ad units in your app.
Step 1. Integrate the Plugin and Mediation Adapters
There are two ways to integrate:
- The best option is using the SDK Manager and is the recommended method.
- However, we also provide instructions for integrating the plugin and adapters manually.
Starting with v. 5.5.0 of the MoPub Unity Plugin, we include the Jar Resolver for dependency resolution. Read more about the Jar Resolver tool below.
Regardless of the integration option you take, ensure the necessary third-party dependencies outlined in the respective Android and iOS sections of our documentation are included in your Unity project. Missing libraries can result in unexpected app and SDK behaviors.
Option 1. Use the SDK Manager (Recommended)
We strongly recommend using the SDK Manager, which we introduced with our 5.5.0 release of the MoPub Unity plugin. Use this new interface to automatically download and install the correct versions of the MoPub SDK, the mediation SDKs, and the associated mediation adapters. The SDK Manager also detects your currently installed versions and prompts you to update any outdated SDKs and adapters.
We support mediation SDKs that are distributed on JCenter and CocoaPods. For SDKs that are only available via direct download from the ad network’s homepage (indicated by [?] buttons in the SDK Manager), you will continue to integrate them manually. The SDK Manager lets you download the
.unitypackage archive that has the adapters. All you need to do is download and place the corresponding mediation SDKs in
Assets/Plugins/Android (Android) or
If you are upgrading from an earlier version of the MoPub Unity plugin, follow the instructions here to delete old directories.
From the Unity menu bar, select MoPub → Manage SDKs.
Click Install for any mediation network you want to integrate. Doing so downloads the desired network’s
.unitypackagearchive containing the adapters, as well as the dependencies XML required for the Jar Resolver.
Option 2. Integrate Manually
Download the latest MoPub Unity plugin here.
To import the MoPub Unity plugin, double-click on the
MoPubUnityPlugin.unitypackage, or go to Assets → Import Package → Custom Package. Keep all the files in the Importing Package window selected, and click Import.
- If you do not use mediation, skip this step.
- Download the mediation adapters for the corresponding platform you are building for. On Android, adapters are released as AAR files. On iOS, adapters are released as .h and .m files. Once downloaded, drag and drop the adapter files to the corresponding directories listed in step 4 below.
- Download the ad network SDK binaries by navigating to dedicated ad network page (e.g. https://developers.mopub.com/publishers/mediation/networks). Ensure you are importing that network’s platform SDKs (Android and iOS), and not its Unity SDK/plugin. Make sure you are using the certified version by referencing the Mediation Integration Tool.
Place any required binaries in your Unity project according to the file extensions, as shown:
SDK File Type Path to place the network SDKs Note Android
[UNITY PROJECT ROOT]/Assets/Plugins/Android
If required by any libraries, add Google Play services aars to this directory. iOS
[UNITY PROJECT ROOT]/Assets/Plugins/iOS
Manually add any required frameworks to your project in Xcode if needed.
(Note: iOS publishers using MoPub plugin version 5.x with a Unity version below 2017.1 must update to MoPub plugin version 5.0.1 or higher, and review the preceding steps.)
For Android, resolve any pending dependencies by using the
Assets > Play Services Resolver > Android Resolver > Force Resolveoption.
- Build and run your Unity project.
Step 2. Initialize the SDK
Follow these instructions to initialize the SDK.
Step 3. Configure Ad Units in Your App
Depending on the ad format you are integrating, load the plugin for it as shown below:
MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits); MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits); MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits); MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
Then, follow the next steps to finish integrating that ad format:
MoPub SDK imposes minimum wait times in between subsequent requests when an ad request is not filled. To avoid this from happening please follow these steps.
Note About Unity Build Systems
To avoid Android build issues due to dex list being too large, please ensure you have switched to Gradle in
Build Settings > Android > Build System.
About the Jar Resolver
Both integration options (the SDK Manager and the manual integration) download the desired network’s
.unitypackage archive containing the adapters, as well as the dependencies XML required for the Jar Resolver, used for dependency resolution. Once the package’s content is imported, depending on the build platform you have specified in Unity, the Jar Resolver will handle resolving the dependencies differently:
For Android, the Jar Resolver downloads adapter and SDK JARs/AARs to
Note that there is a known issue with the Jar Resolver when resolving Android dependencies. It occasionally leaves the progress bar up indefinitely (or until you exit Unity) even though the resolution process has completed. Unity itself is not blocked, but a side effect is that Unity dialog boxes (like the SDK Manager window) can’t be closed with the usual red close button in the top left of the window; you must use the OK or Done button in the dialog.
For iOS, the Jar Resolver works during the build process. Xcode runs specified
podcommands to fetch adapter and SDK pods (the Jar Resolver attempts to install CocoaPods itself if it doesn’t detect it.)
In Assets → Play Services Resolver, you can find a settings dialog for the Jar Resolver, where you can customize its behavior, including whether to perform resolution automatically (for Android), and whether to enable verbose logging. The latter option is recommended if you experience any difficulties using the Resolver.
You may notice that libraries are downloaded when you try to delete them from disk. This is an intended behavior of the Jar Resolver. To permanently delete a downloaded adapter or network SDK, delete the network’s
Last updated January 10, 2020
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2020 MoPub (a division of Twitter, Inc.)