Knowledge base

Integration Guide for Android

This guide will show you how to integrate Unity Ads into an Android Studio project.

Download the latest Unity Ads here.

Android video tutorial available on YouTube (6:57)

Example project can be found on GitHub

Contents:

If you are upgrading your integration from Unity Ads 1.5.x, please refer to the Android transition guide instead.

Quickstart guide

Create a new game project in the Unity Ads dashboard

Log into the [Unity Ads Dashboard][50] using your UDN account.

  • If you don't have a UDN account yet, sign up [here][52].

From the Dashboard, create a new game project.

NOTE: Leave the "targets children under 13" option OFF unless your game is specifically designed for children in the USA. Games for all ages are not required to enable COPPA compliance.

Locate the (7-digit) Game ID by selecting your game project. You will use this number to activate Unity Ads.

Locate your placement IDs by selecting a game ID (iOS or Android), then clicking the Placements tab. Initially, each game ID has two placements:

  • video (default / skip video after 5 seconds)
  • rewardedVideo (no skip option)

Enable test mode for each game ID under the settings tab.

Apple/Play Store Game ID > Settings > Test mode: Force ON

Integrate Unity Ads in Android Studio:

  1. Download the latest release binaries from GitHub, specifically unity-ads.aar.
  2. Create or open your existing Android project in Android Studio.
  3. Add new module and import unity-ads.aar. Name the module "unity-ads" for example.
  4. Open Module Settings for the app and add "unity-ads" module as a dependency.
  5. Add the following imports to your java Activity file:
    • import com.unity3d.ads.IUnityAdsListener;
    • import com.unity3d.ads.UnityAds;
  6. Add implements IUnityAdsListener to your class, and have Android Studio generate the required callback methods
  7. Within the activity that implements IUnityAdsListener, initialize Unity Ads by calling UnityAds.initialize(this, gameId, this) where gameId is a String value set to the game ID of the Android platform, found under your project in the Unity Ads dashboard.
    Note: Unity Ads is only initialized once. SDK 2.0 has a more robust network retry logic. So you can safely initialize even without network connectivity. The SDK will request ads when the network becomes available.
  8. The following code will then show an ad for your default placement:
    if (UnityAds.isReady()) { UnityAds.show(this); }

Unity Ads SDK 2.0 takes activity argument in each show method invocation (this in the above example).

See Unity Ads Android API reference for more information on the API, e.g. showing ads for different placements and refer to the example application for an example on how to implement the Unity Ads SDK into your project.

Integrating without Android Studio

If you can't use the AAR packages with your build system, we also provide the same resources in a ZIP file, unity-ads.zip in GitHub releases. You need to do three things to use Unity Ads successfully.

  • Include classes.jar in your build.
  • Manually merge manifest from AndroidManifest.xml. Make sure you include both AdUnitActivity and AdUnitSoftwareActivity activities. You also need to add INTERNET and ACCESS_NETWORK_STATE permissions.
  • If you are using ProGuard, add all lines from proguard.txt to your ProGuard configuration.

Unity Ads Android Advanced Guides

For Additional questions, please contact us at unityads-support@unity3d.com

Still need help? Get in touch!
Last updated on 30th Mar 2017