Interstitial Ad Integration Guide(Android Studio) - united-adstir/AdStir-Integration-Guide-Android GitHub Wiki

Important: About SDK Update

When update the SDK, strongly recommended update all files in SDK package.

Supported OS version

Android 4.4 or later.

Partner ad netowrks

Please see the page of here

Setup

Before integration

Please see Initial-Setting to setup Google Play services and download SDK.

Project setting

Set Compile SDK Version to API 18.

Set Compile SDK Version to API 18.

Add libraries

Import all .aar, .jar files with following steps.

  1. Select menu File -> New -> New Module -> Import JAR / AAR Package
  2. Select library from package.
  3. Open Project Structure (File -> Project Structure)
  4. Select app tab, and add dependency for library that imported.
  5. Repeat for all .aar, .jar packages.

And copy armeabi folder manually to Project Root -> app -> src -> main -> jniLibs

And copy armeabi folder manually to Project Root -> app -> src -> main -> jniLibs

ProGuard rules

If you are using ProGuard, please add following rules to proguard-rules.pro (or any other configuration file).

# adstir
-dontwarn com.ad_stir.**
-keep class com.ad_stir.** { *; }
-keep interface com.ad_stir.** { *; }

# google
-keep class com.google.android.gms.ads.** { *; }
-keep class android.support.customtabs.** { *; }

# adcorsa
-keep interface com.glossomads.**
-keep class com.glossomads.** { *; }
-dontwarn com.glossomads.**
-dontwarn android.app.Activity

# applovin
-dontwarn com.applovin.**
-keep class com.applovin.**.*

# unity-ads
-keepattributes SourceFile,LineNumberTable
-keepattributes JavascriptInterface
-keep class android.webkit.JavascriptInterface {
   *;
}
-keep class com.unity3d.ads.** {
   *;
}

# maio
-dontwarn jp.maio.**
-keep class jp.maio.** { *; }
-keep interface jp.maio.** { *; }

# tapjoy
-keep class com.tapjoy.** { *; }
-keepattributes JavascriptInterface
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class com.google.android.gms.ads.identifier.** { *; }
-dontwarn com.tapjoy.internal.**

For MoPub Ads integration

Before MoPub Ad integration, please contact your account manager or contact from Contact Form.

Add SDK to project

  1. Select menu File -> New -> New Module -> Import JAR / AAR Package
  2. Select mopub-sdk.aar, androidwebviewmediation-adapter-mopub.aar.
  3. Open Project Structure (File -> Project Structure)
  4. Select app tab, and add dependency for library that imported.

gradle settings(MoPub)

Add following settings to app/build.gradle.

repositories {
  ...
  jcenter()
}

dependencies {
  ...
 // ads-lite, or using ads
  compile 'com.google.android.gms:play-services-ads-lite:x.x.x'

  compile 'com.mopub.volley:mopub-volley:1.1.0'
  compile 'com.android.support:recyclerview-v7:x.x.x'
  compile 'com.google.android.exoplayer:exoplayer:r1.5.6'
}

gradle settings(Nend)

Add following settings to app/build.gradle.

repositories {
  ...
  jcenter()
}

dependencies {
  ...
 // ads-lite, or using ads
  compile 'com.google.android.gms:play-services-ads-lite:x.x.x'

  compile 'com.android.support:recyclerview-v7:x.x.x'
  compile 'com.android.support:cardview-v7:x.x.x'
  compile 'com.android.support:percent:x.x.x'
}

ProGuard rules(MoPub)

If you are using ProGuard, please add following rules to proguard-rules.pro (or any other configuration file).

-dontwarn com.mopub.**
-keep class com.mopub.** {*;}

Integration

Implementation

import com.ad_stir.interstitial.AdstirInterstitial;
import com.ad_stir.interstitial.AdstirInterstitialListener;

private AdstirInterstitial interstitial;

// Event listener for AdstirInterstitial
private AdstirInterstitialListener listener = new AdstirInterstitialListener() {
    @Override
    // You can show interstitial ad after loaded.
    public void onLoad(int spot_no) {
        if(interstitial.canShow()){
            interstitial.show();
        }
    }

    @Override
    public void onFailed(int spot_no) {}
    @Override
    public void onStart(int spot_no) {}
    @Override
    public void onStartFailed(int spot_no) {}
    @Override
    public void onFinished(int spot_no) {}
    @Override
    public void onClose(int spot_no) {}
};

@Override
// Load ad
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.xxxx);

    // Initialize spot number using in this activity.
    int[] spotIds = { 1, 2 };
    AdstirVideoAds.init(this, "MEDIA-xxxxxx", spotIds);
    // Instantiate class per each spot.
    adstirInterstitial = new AdstirInterstitial(this, "MEDIA-xxxxxx", 1);
    // Set listener.
    adstirInterstitial.setAdstirInterstitialListener(listener);
    // Load ad.
    adstirInterstitial.load();
}

// Stop and resume the ad
@Override
protected void onResume() {
    if(adstirInterstitial != null) adstirInterstitial.resume();
    super.onResume();
}

@Override
protected void onPause() {
    if(adstirInterstitial != null) adstirInterstitial.pause();
    super.onPause();
}

// Destroy class
@Override
protected void onDestroy() {
    if(adstirInterstitial != null) adstirInterstitial.destroy();
    super.onDestroy();
}

Class Reference

See also API Reference.

FAQ

I got java.lang.ClassNotFoundException

Maybe adapter library or 3rd party SDK is missing. Please check Add libraries section.