Integration guide for Unity Ads 2.0 (Android) - Schinizer/Unity-Ads-Native-Android GitHub Wiki

Overview

Unity Ads is a monetization tool that allows you to display video trailers of other games to your users, earn money with each view, and reward users with a virtual item. To monetize your users with Unity Ads, the product must be integrated into your game. This document will guide you through that process.

This guide will assume you are using Android Studio with gradle, using Java.

Prerequisites

  • You will first need to download the .aar package from here.
  • You will need a proper project set up before integrating Unity Ads.

Setup

Add a new module (File -> New -> New Module...) and select Import .JAR/.AAR Package, then press next.

Navigate to and select the downloaded .aar package. You can keep the Subproject name as default or change it. Press finish to import the module.

Add the following to your app/build.gradle

compile project(':unity-ads') // Your Subproject name

And you are done setting up.

Note: Unfortunately there is no gradle dependency available at the point of time this guide is written. You will have to import this package every time there is an update available

Initialization

Unity Ads needs to be initialized through the network before it can be used.

Add the following in the onCreate() function in your Activity.

String gameID = ""; // Your GameID from the dashboard

UnityAds.initialize(this, gameID, new IUnityAdsListener() { // this refers to an Activity
    @Override
    public void onUnityAdsReady(String s) {
    }

    @Override
    public void onUnityAdsStart(String s) {
    }

    @Override
    public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
    }

    @Override
    public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
    }
});

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.

Once onUnityAdsReady() is called, you are ready to use Unity Ads!

Usage

To display an Unity Ads, simply just call

if (UnityAds.isReady()) {
    UnityAds.show(this); // this refers to an Activity
}

See [Unity Ads Android API reference] (https://github.com/Unity-Technologies/unity-ads-android/wiki/sdk_android_api_reference) for more information on the API, e.g. showing ads for different placements.

Sample App

You may find the sample app here