Incentiveized Video 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.

When using 2.10.1 or earlier version

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.** { *; }

# vungle
-dontwarn com.vungle.**
-keep class com.vungle.** { *; }
-keep class javax.inject.*
-keepattributes *Annotation*
-keepattributes Signature
-keep class dagger.*


# 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.**

# nend
-keep class net.nend.android.** { *; }
-dontwarn net.nend.android.**

# imobile
-keep class jp.co.imobile.** {*;}
-dontwarn jp.co.imobile.**

-keepattributes EnclosingMethod

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'
}

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.** {*;}

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'
}

Integration

Implementation Sample

// import required classes
import com.ad_stir.videoreward.AdstirVideoReward;
import com.ad_stir.videoreward.AdstirVideoRewardListener;

private static final String TAG = "Adstir";

private boolean isRewarded = false;
private AdstirVideoReward adstirVideoReward;

// Define listner
private AdstirVideoRewardListener listener = new AdstirVideoRewardListener() {
// You can show incentivized video ad after loaded.
public void onLoad(int spot_no) {
    if(adstirVideoReward.canShow()){
    adstirVideoReward.showRewardVideo();
    }
    }

    public void onFailed(int spot_no) {}
    public void onStart(int spot_no) {}
    public void onStartFailed(int spot_no) {}
    public void onFinished(int spot_no) {}
    public void onReward(int spot_no) {
    isRewarded = true;
    }
    public void onRewardCanceled(int spot_no) {}
    public void onClose(int spot_no) {}
};


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

    // Set user identifier for Server-Side Callback
    // You have to specify user identifier that your API identify the user.
    // AdstirVideoAds.setMediaUserID("XXXXXXXXXXX");

    // Initialize spots using this activity.
    int[] spotIds = { 1, 2 };
    AdstirVideoAds.init(this, "MEDIA-xxxxxx", spotIds);
    // Create instance per spot ID.
    adstirVideoReward = new AdstirVideoReward(this, "MEDIA-xxxxxx", 1);
    // Add listener defined before.
    adstirVideoReward.setAdstirVideoRewardListener(listener);
    // Start loading...
    adstirVideoReward.load();
}

// Resume and Pause, Destroy
@Override
protected void onResume() {
    if(adstirVideoReward != null) {
        adstirVideoReward.resume();
        adstirVideoReward.load();
    }
    if(isRewarded) {
        isRewarded = false;
        Log.d(TAG, "Reward success.");
    }
    super.onResume();
}

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

@Override
protected void onDestroy() {
    if(adstirVideoReward != null) adstirVideoReward.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.