Migrating the Vungle Android SDK from v. 5 to v. 6

Welcome to migration guide for Vungle Android SDK v6! The new SDK has been completely rewritten to be both robust and lightweight. Use this document to guide you through the SDK upgrade because there are significant changes in both API and integration details. If this is a brand new integration and you are not migrating from the v5 SDK, use the Integrating Vungle Android SDK v6 guide instead of this one.

In this article:

GDPR: Recommended Implementation

As of May 25th, the General Data Protection Regulation (GDPR) will be enforced in the European Union. To comply with GDPR, developers have two options.

  • Option 1 (recommended): Publisher controls the GDPR consent process at the user level, then communicates the user’s choice to Vungle. To do this, developers can collect the user’s consent using their own mechanism, and then use Vungle APIs to update or query the user’s consent status. Refer to the GDPR Recommended Implementation Instructions section for details.

  • Option 2: Allow Vungle to handle the requirements. Vungle will display a consent dialog before playing an ad for a European user, and will remember the user’s consent or rejection for subsequent ads.

Before You Begin 

Release Highlights

  • Fast: Initialization and ad caching performance is up to five times faster than in v5
  • Lightweight: reduced method counds
    • Core SDK: 750 methods
    • Full integration including third-party libraries: ~4000 methods
  • GDPR compliance: Vungle provides two options for obtaining user consent: either Vungle or the Publisher can control this process. New API calls have been added.


  • Android 4.0 (Ice Cream Sandwich - API version 14) or later 

Sample App

Step 1. Change Vungle SDK in Your Project

Depending on your project setup, use the AAR integration via Maven or JAR for manual integration.

Option 1. Gradle Integration 

dependencies {
    compile 'com.github.vungle:vungle-android-sdk:6.2.3'
    compile 'com.google.android.gms:play-services-basement:11.0.1' // Required
    compile 'com.google.android.gms:play-services-location:11.0.1' // Recommended

Skip to "Step 2. Import the Vungle SDK."

Option 2. JAR Integration

Download Vungle SDK v6 and replace the old Vungle SDK and third-party dependency JAR files with the new SDK and libraries. Please pay attention to the addition and removal of required libraries, as well as version updates.

v5 Libraries v6 Libraries
image3.png image2.png

Compile all JAR files from the SDK package download.

dependencies {
    // Vungle SDK
    compile files('libs/vungle-android-sdk-6.2.5.jar')          
    // Required Third-party Dependencies
    compile files('libs/android-job-1.2.0.jar')
    compile files('libs/cat-1.0.5.jar')
    compile files('libs/converter-gson-2.2.0.jar')
    compile files('libs/fetch-1.1.5.jar')
    compile files('libs/gson-2.7.jar')
    compile files('libs/logging-interceptor-3.7.0.jar')
    compile files('libs/okhttp-3.7.0.jar')
    compile files('libs/okio-1.12.0.jar')
    compile files('libs/retrofit-2.2.0.jar')
    compile files('libs/VNG-moat-mobile-app-kit-2.2.0.jar')
    // Google Play Services
    compile 'com.google.android.gms:play-services-gcm:11.0.4'       // Required
    compile 'com.google.android.gms:play-services-basement:11.0.4'  // Optional
    compile 'com.google.android.gms:play-services-location:11.0.4'  // Optional


Modify your AndroidManifest.xml. 

<!--Required Permissions-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!--Optional Permissions-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application
android:networkSecurityConfig="@xml/network_security_config" > <activity android:name=".MainActivity">
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</activity> <!-- Google Play Services -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> <!-- Vungle -->
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!-- android-job -->
android:permission="android.permission.BIND_JOB_SERVICE" />
android:permission="android.permission.BIND_JOB_SERVICE" />
android:exported="false" />
android:exported="false" >
<!-- Keep the filter for legacy intents -->
<action android:name="com.evernote.android.job.v14.RUN_JOB" />
<action android:name="net.vrallev.android.job.v14.RUN_JOB" />
android:exported="false" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE" >
<action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
android:permission="android.permission.BIND_JOB_SERVICE" /> </application>

Step 2. Import the Vungle SDK 

// v5 Import SDK
import com.vungle.publisher.*;

// v6 Import SDK
import com.vungle.warren.*; 

Step 3. Initialize the Vungle SDK

Previously, to initialize, you had to first grab a Vungle SDK instance and issue init(). This method took the Vungle Application ID, array of string containing the Placement Reference IDs and VungleInitListener, like this: 

// v5 Initialization
private final VunglePub vunglePub = VunglePub.getInstance();
private final String[] placement_array = {"PLACEMENT_1", "PLACEMENT_2", "PLACEMENT_3"};
vunglePub.init(this, app_id, placement_array, new VungleInitListener() {
    public void onSuccess() { }

        public void onFailure(Throwable e) { }

The new initialization method takes different parameters and in different order:

  • List of string of Placement Reference IDs used
  • Vungle Application ID
  • Application context
  • InitCallback
    • onSuccess: notifies when SDK has successfully initialized
    • onError: notifies when the initialization has failed
      • throws IllegalArgumentException if InitCallback is null
      • throws VungleException if required arguments are missing or invalid
    • onAutoCacheAdAvailable: notifies when the auto-cached placement has an ad available to play

The onAutoCacheAdAvailablecallback is available as part of the initialization callback because the SDK will continuously attempt to cache an ad for the auto-cached placement whenever an ad is not pre-cached. This includes when the SDK is started for the first time or when the pre-cached ad for the placement has been played. This will remain true until the process dies or the Vungle instance is reclaimed by garbage collection. For all other placements that are not auto-cached placements, loadAd must be explicitly issued as described in “Step 5. Load an Ad.” 

// v6 Initialization
private final List<String> placement_collection = Arrays.asList("PLACEMENT_1", "PLACEMENT_2", "PLACEMENT_3");

Vungle.init(placement_collection, app_id, this.getApplicationContext(), new InitCallback() {
    public void onSuccess() {
        // Initialization has succeeded and SDK is ready to load an ad or play one if there
        // is one pre-cached already

    public void onError(Throwable throwable) {
        // Initialization error occurred - throwable.getMessage() contains error message

    public void onAutoCacheAdAvailable(String placementId) {
        // Callback to notify when an ad becomes available for the auto-cached placement
        // NOTE: This callback works only for the auto-cached placement. Please use
        // LoadAdCallback interface for other placements

You can check whether Vungle SDK is initialized anytime by calling the isInitialized method:

public static boolean isInitialized() 

Step 4. Event Listener

The global VungleAdEventListener in v5 SDK has been replaced with two independent callbacks for load and play events in SDK v6. Please remove the VungleAdEventListener implementation for SDK v5 from your project: 

// Remove v5 Event Listener
public class FirstActivity extends android.app.Activity {

    private final VungleAdEventListener vungleListener = new VungleAdEventListener(){

        public void onAdEnd(String placementReferenceId, boolean wasSuccessfulView, boolean wasCallToActionClicked) { }

        public void onAdStart(String placementReferenceId) { }

        public void onUnableToPlayAd(String placementReferenceId, String reason) { }

        public void onAdAvailabilityUpdate(String placementReferenceId, boolean isAdAvailable) { }

    public void onDestroy() {

Implement LoadAdCallback for ad load events and PlayAdCallback for ad play events now if you want to use generic callback for all events. Otherwise, skip to “Step 5. Load an Ad” to implement inline callbacks. 

// Implement v6 LoadAdCallback
private final LoadAdCallback vungleLoadAdCallback = new LoadAdCallback() {
    public void onAdLoad(String placementReferenceId) {
        // Placement reference ID for the placement to load ad assets

    public void onError(String placementReferenceId, Throwable throwable) {
        // Placement reference ID for the placement that failed to download ad assets
        // Throwable contains error message


// Implement v6 PlayAdCallback
private final PlayAdCallback vunglePlayAdCallback = new PlayAdCallback() {
    public void onAdStart(String placementReferenceId) {
        // Placement reference ID for the placement to be played

    public void onAdEnd (String placementReferenceId, boolean completed, boolean isCTAClicked) {
        // Placement reference ID for the placement that has completed ad experience
        // completed has value of true or false to notify whether video was
        // watched for 80% or more
        // isCTAClkcked has value of true or false to indicate whether download button
        // of an ad has been clicked by the user

    public void onError(String placementReferenceId, Throwable throwable) {
        // Placement reference ID for the placement that failed to play an ad
        // Throwable contains error message

Step 5. Load an Ad

Loading an advertisement is essentially the same in both versions except for the major distinction that in v6, a per-load callback is allowed instead of depending on the global VungleAdEventListener from v5. The LoadAdCallback will be notified about the load state for the call to which it was assigned. The v6 SDK only references this callback and does not store it anywhere; it is the responsibility of the caller to ensure that the callback is managed properly. 

// v5 loadAd
public void loadAd(@NonNull String placementReferenceId)

// v6 loadAd
public static void loadAd(@NonNull final String id, @Nullable LoadAdCallback callback) 

The SDK manages the ad asset download for the auto-cached placement, so there is no need to invoke this method for the auto-cached placement. For all other placements, the loadAd method must be invoked and completed successfully before the SDK can play an ad for the placement. The onAdLoad callback will be triggered when this happens. 

// v6 Load Ad Implementation
if (Vungle.isInitialized()) {
    Vungle.loadAd("PLACEMENT_ID", new LoadAdCallback() {
        public void onAdLoad(String placementReferenceId) { }

        public void onError(String placementReferenceId, Throwable throwable) { }

Step 6. Check Ad Availability

Check for availability has remained essentially the same as in v5, with the only difference being that the method is now a static method instead of an instance method. 

 // v5 isAdPlayable
public boolean isAdPlayable(@NonNull final String placementReferenceId)

// v6 canPlayAd
public static boolean canPlayAd(@NonNull String id) 

Step 7. Play an Ad

Similar to the change in loading an ad, playing an ad requires the same information as in v5, with the option to pass a PlayAdCallback to the method, which will be notified of success or errors during ad playback. 

// v5 playAd
public void playAd(@NonNull String placementReferenceId, @Nullable AdConfig adConfig)

// v6 playAd
public static void playAd(@NonNull final String id, final AdConfig settings, @Nullable final PlayAdCallback listener) 

You should always check ad availability by calling the canPlayAd method before invoking the playAd method. You must also make sure that an additional playAd is not issued before your receive an onAdEnd or an onError callback from the initial playAd call, because the ad will not render properly if playAd is repeatedly called in quick succession. 

// v6 Play Ad Implementation
if (Vungle.canPlayAd("PLACEMENT_ID")) {
    Vungle.playAd("PLACEMENT_ID", new AdConfig, new PlayAdCallback() {
        public void onAdStart(String placementReferenceId) { }

        public void onAdEnd(String placementReferenceId, boolean completed, boolean isCTAClicked) { }

        public void onError(String placementReferenceId, Throwable throwable) { }

Step 8. Configuration Options

Ad Playing Options

The following table shows all the available AdConfig options. 




true if back button should be enabled before ad close button appears, false otherwise


takes an Integer value that is greater or equal to 0 that specifies time in seconds for Flex-View ad to automatically close itself


true if immersive mode will be enabled for KitKat+ devices, false otherwise


true if the video ad is supposed to auto-rotate, false to follow video ad orientation


true if the video should start with its audio settings matching those of your enclosing application, false if it should start muted regardless


takes an Integer value of ordinal count to track the number of ads that has been played in same session


true if the video transition animation should be enabled, false if it should be disabled

Customizing Rewarded Ads

The pop-up message dialog for rewarded ads was configurable with the AdConfig object in v5, but v6 provides a new method, setIncentivizedFields, instead. 

public static void setIncentivizedFields(@Nullable String userID, @Nullable String title, @Nullable String body, @Nullable String keepWatching, @Nullable String close) 

Close Flex-View Ad

Flex-View can be programmatically closed by issuing the closeFlexViewAd method with the Placement Reference ID that is currently playing the Flex-View ad. 

public static boolean closeFlexViewAd(@NonNull final String placementReferenceId) 

List of Valid Placements

A helper method that returns Collection of String containing all valid Placement Reference IDs for the current session. 

public static Collection<String> getValidPlacements() 

ProGuard Rules

# Vungle
-keep class com.vungle.warren.** { *; }

# Evernote
-dontwarn com.evernote.android.job.gcm.**
-dontwarn com.evernote.android.job.GcmAvailableHelper

-dontwarn com.google.android.gms.ads.identifier.**

-keep public class com.evernote.android.job.v21.PlatformJobService
-keep public class com.evernote.android.job.v14.PlatformAlarmService
-keep public class com.evernote.android.job.v14.PlatformAlarmReceiver
-keep public class com.evernote.android.job.JobBootReceiver
-keep public class com.evernote.android.job.JobRescheduleService

-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keep class com.google.android.gms.internal.** { *; }

# Moat SDK
-keep class com.moat.** { *; }
-dontwarn com.moat.**

GDPR Recommended Implementation Instructions

To use Vungle APIs to update or query the user’s consent status (as recommended in Option 1 of Vungle's GDPR: Recommended Implementation), use these functions:

  • // To set the user's consent status to opted in:
    // To set the user's consent status to opted out:
    // To find out what the user's current consent status is:
    // This will return null if the GDPR Consent status has not been set
    // Otherwise, it will return Vungle.Consent.OPTED_IN or Vungle.Consent.OPTED_OUT
    UpdateConsentStatus? currentStatus = sdkInstance.GetCurrentConsentStatus();
    Vungle.Consent currentStatus = Vungle.getConsentStatus();
Have more questions? Submit a request