Get Started with 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
- 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.
Note that the MoPub Unity Plugin is not supported on Unity Editor version 2018.3.0f2 (for more context, refer to the Unity Issue Tracker).
High-Level Steps to Integrate
- 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.
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 use mediation, download the mediation adapters 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.
To import the mediation adapters, double-click on the desired network’s
.unitypackageor go to Assets → Import Package → Custom Package.
To mediate third-party ad networks, download the certified network SDKs from the link in the MoPub Mediation Integration Tool > Your Network Name > Learn More. Ensure you are importing that network’s platform SDKs (Android and iOS), and not the Unity SDK/plugin. Make sure you are using the cerified version.
Place the network SDKs 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 networks, add Google Play services aars to this directory. Android
[UNITY PROJECT ROOT]/Assets/Plugins/Android/mopub-support/libs
If required by networks, add Google Play services jars to this directory. iOS
[UNITY PROJECT ROOT]/Assets/Plugins/iOS
Manually add 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.)
Build and run your Unity project. For iOS, after exporting your project into Xcode, make sure that
MoPubSDKFramework.frameworkis in the
Embedded Binarieslist; if not, click the + button to add it.
Make sure that the
MoPubSDKFramework.frameworkand other network frameworks are in the Linked Frameworks and Libraries list; if not, click the + button to add them.
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:
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 March 11, 2019
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.
© 2019 MoPub (a division of Twitter, Inc.)