Integrate Vungle SDK for Android or Amazon

Before You Begin

The Vungle SDK has been built and tested up to API version 31, Android 12.

Google Privacy Policy Compliance

To ensure compliance with the Google Privacy Policy changes that will go into effect April 1, 2022:

  • Mixed-audience apps: We strongly recommend upgrading to Vungle SDK v.6.10.4 or higher and using the SDK COPPA API to inform Vungle if a user is under the age 13.
  • Family apps: We strongly recommend upgrading to Vungle SDK v.6.10.4 or higher.

Requirements

  • Android 5.0 (API version 21) or higher
  • Amazon OS 5.4 or higher
  • The integration requires a LIftoff account, so create an account if you haven’t already done so, and create a new Android or Amazon app in your account. Refer to the Add Your Apps and Placements section of our Using the Publisher Dashboard article to learn how to set up placements in the Liftoff Monetize dashboard.

Download the SDK

Download the Vungle SDK for Android or Amazon.

Reference: Sample App and Java Doc

Sample app: Refer to the sample app we have provided as you integrate: https://github.com/Vungle/Android-SDK.

JavaDoc: https://vungle.github.io/vungle-android-sdk/javadoc.

Step 1. Include the Vungle SDK in Your Project

You can integrate the early access Vungle SDK either as a Gradle dependency, or manually using a JAR or AAR integration. 

// API version compatibility
minSdkVersion 21
compileSdkVersion 31
targetSdkVersion 31

Gradle

Open the project-level build.gradle, and ensure that the Maven Central repository is added:
allprojects {
  repositories {
    mavenCentral()
  }
}
Open the app-level build.gradle file for your app, and add compile dependencies in the dependencies section:
dependencies { 
  // Vungle SDK
  implementation 'com.vungle:publisher-sdk-android:6.12.0'
 
  implementation 'androidx.core:core:1.1.0'
  implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

  // When appcompat is being used, core and localbroadcastmanager are the dependencies
  // that is getting included
  // implementation 'androidx.appcompat:appcompat:1.3.0'

  // Recommended for SDK to be able to get Android Advertising ID
  implementation 'com.google.android.gms:play-services-basement:18.0.1'
  implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
  
  // Starting with v6.10.3, the Vungle SDK supports app set ID. 
  // To take advantage of this feature, include Google Play Services tasks and appset libraries 
  // inside build.gradle
  implementation 'com.google.android.gms:play-services-tasks:18.0.1'
  implementation 'com.google.android.gms:play-services-appset:16.0.2'  
}

JAR

  1. Download the Vungle SDK and unzip it. From the libs folder, copy all the .jar files, and add them to your project libs folder:
    • vungle-android-sdk-6.12.0.jar
    • gson-2.8.6.jar
    • okhttp-3.14.9.jar
    • okio-1.17.3.jar
  2. Open the app-level build.gradle file for your app, and add other dependencies in the dependencies section.
    dependencies {
      // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.12.0.jar')
    
      // Required Third-party Dependencies
      implementation files('libs/gson-2.8.6.jar')
      implementation files('libs/okhttp-3.14.9.jar')
      implementation files('libs/okio-1.17.3.jar')
    
      implementation 'androidx.core:core:1.1.0'
      implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    
      // When appcompat is being used, core and localbroadcastmanager are the dependencies
      // that is getting included
      // implementation 'androidx.appcompat:appcompat:1.3.0'
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:18.0.1'
      implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
      
      // Starting with v6.10.3, the Vungle SDK supports app set ID. 
      // To take advantage of this feature, include Google Play Services tasks and appset libraries 
      // inside build.gradle
      implementation 'com.google.android.gms:play-services-tasks:18.0.1'
      implementation 'com.google.android.gms:play-services-appset:16.0.2'
    }
  3. Update your AndroidManifest.xml by adding the following lines and assigning the application item name to your application class name:
    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="31" />
    
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <application
        android:hardwareAccelerated="true"
        android:supportsRtl="true" >
        <activity
            android:name="com.vungle.warren.ui.VungleActivity"
            android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    
        <provider
            android:name="com.vungle.warren.utility.VungleProvider"
            android:authorities="${applicationId}.vungle-provider"
            android:exported="false" />
    </application>

AAR

  1. Download the Vungle SDK and unzip it. From the libs folder, copy SDK .aar and all .jar dependencies, and add them to your project libs folder:
    • vungle-android-sdk-6.12.0.aar
    • gson-2.8.6.jar
    • okhttp-3.14.9.jar
    • okio-1.17.3.jar
  2. Open the app-level build.gradle file for your app, and add other dependencies in the dependencies section.
    dependencies {
      // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.12.0.aar')
    
      // Required Third-party Dependencies
      implementation files('libs/gson-2.8.6.jar')
      implementation files('libs/okhttp-3.14.9.jar')
      implementation files('libs/okio-1.17.3.jar')
    
      implementation 'androidx.core:core:1.1.0'
      implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    
      // When appcompat is being used, core and localbroadcastmanager are the dependencies
      // that is getting included
      // implementation 'androidx.appcompat:appcompat:1.3.0'
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:18.0.1'
      implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
      
      // Starting with v6.10.3, the Vungle SDK supports app set ID. 
      // To take advantage of this feature, include Google Play Services tasks and appset libraries 
      // inside build.gradle
      implementation 'com.google.android.gms:play-services-tasks:18.0.1'
      implementation 'com.google.android.gms:play-services-appset:16.0.2'  
    }

Step 2. Import the Vungle SDK

import com.vungle.warren.Vungle;
import com.vungle.warren.AdConfig;              // Custom ad configurations
import com.vungle.warren.InitCallback;          // Initialization callback
import com.vungle.warren.LoadAdCallback;        // Load ad callback
import com.vungle.warren.PlayAdCallback;        // Play ad callback
import com.vungle.warren.VungleNativeAd;        // MREC ad
import com.vungle.warren.Banners;               // Banner ad
import com.vungle.warren.VungleBanner;          // Banner ad
import com.vungle.warren.Vungle.Consent;        // GDPR consent
import com.vungle.warren.VungleSettings         // Minimum disk space
import com.vungle.warren.error.VungleException  // onError message

Step 3. Add Code

Initialize the SDK

init init with optional VungleSettings
public static void init(@NonNull final String appId,
                        @NonNull final Context context,
                        @NonNull final InitCallback callback)

The initialization method takes the following parameters:

  • Vungle application ID
  • Application context
  • InitCallback
    • onSuccess: notifies when the SDK has successfully initialized
    • onError: notifies when the initialization has failed
      • Throws IllegalArgumentException if InitCallback is null.
    • onAutoCacheAdAvailable: notifies when the auto-cached placement has an ad available to play
  • VungleSettings (optional)
6.5.0 & above Legacy
Vungle.init(appId, getApplicationContext(), new InitCallback() {
  @Override
  public void onSuccess() {
    // SDK has successfully initialized
  }

  @Override
  public void onError(VungleException exception) {
    // SDK has failed to initialize
  }

  @Override
  public void onAutoCacheAdAvailable(String placementId) {
    // Ad has become available to play for a cache optimized placement
  }
};
Overridable Methods Description
onSuccess() Invoked when the SDK has successfully initialized and is ready to load an ad or play one if available.
onError(VungleException exception) Invoked when an error occurs while attempting to initialize the SDK. You will be able to check error messages from getLocalizedMessage of VungleException and use getExceptionCode for debugging.
onAutoCacheAdAvailable(String placementId) Invoked when an ad has become available to play for a cache-optimized placements. Publishers are still expected to explicitly issue loadAd for cache-optimized placements, as described in Load an Ad for a Placement.

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

public static boolean isInitialized()

Integrate Ad Formats

Complete your SDK integration for each ad format you plan to display in your app. Refer to our instructions for each ad format:

Further Customize Your Ads

Follow the instructions in our Advanced Settings article to fine-tune your app's integration with additional configuration options, such as GDPR, CCPA implementation, and many other settings.

 

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?