Knowledge base

(Legacy) Android integration guide

Note: This legacy guide covers Unity Ads integration in Java using the UnityAds API, which is still fully supported. However, Unity recommends using the UnityMonetization API available in SDK versions 3.0+ to take advantage of advanced optimization features. For more information, click here.

This guide will show you how to integrate Unity Ads into an Android Studio project, i.e. when developing native Android apps.

Download the latest Unity Ads here.

Android video tutorial available on YouTube (6:57)

Example project can be found on GitHub


Quickstart guide

Integration Video (6m:57s)

Create a Game Project in the Unity Ads Dashboard

Log into the Unity Ads Dashboard using your UDN account.

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

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;
    • import;
  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 Developer 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()) {; }

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, 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.

For Additional questions, please contact us.

Still need help? Get in touch!
Last updated on 19th Aug 2019