MoPub広告の導入 - united-adstir/AdStir-Integration-Guide-Android GitHub Wiki

対応OS

MoPubはadstir SDK 2.12.0以降をお使いの場合はAndroid 4.4以上の端末に配信されます。 adstir SDK 2.12.0未満をお使いの場合はAndroid 4.1以上の端末に配信されます。

MoPub対応SDKの準備

バンドル版の入手は、担当またはお問い合わせフォームよりご連絡ください。

プロジェクトへSDKの追加

初期設定でbuild.gradleへ記述してSDKを追加した場合は1.で、手動でSDKを追加した場合は2.でプロジェクトへSDKを追加します。

1. build.gradleへ記述してSDKを追加した場合

アプリケーションのモジュールディレクトリにあるbuild.gradleを開き、repositoriesセクションを追加し、dependenciesセクションへ以下のように追記します。 バージョンは変更履歴よりご選択ください。

apply plugin: 'com.android.application'
    ...
android {
        
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    jcenter()
    maven { url 'http://cdnp.ad-stir.com/m2' }
}
dependencies {
    implementation 'com.google.android.gms:play-services-ads:x.x.x'

    // 利用するadstirのSDKバージョンを設定します
    def adstir_version = "x.x.x"
    implementation "com.ad-stir.webviewsdk:adstir-webviewsdk:${adstir_version}"
    implementation "com.ad-stir.mediationadapter:adstir-mediationadapter-mopub:${adstir_version}"

    // ご利用されているライブラリが競合した際は下記のバージョンをご利用されているライブラリのバージョンへ書き換えてください。
    configurations.all {
        resolutionStrategy.force "androidx.legacy:legacy-support-v4:x.x.x"
        resolutionStrategy.force "androidx.annotation:annotation:x.x.x"
        resolutionStrategy.force "androidx.recyclerview:recyclerview:x.x.x"
        resolutionStrategy.force "androidx.appcompat:appcompat:x.x.x"
    }
}

2. 手動でSDKを追加した場合

  1. File -> New -> New Module -> Import .JAR/.AAR Package よりmopub-sdk.aar,androidwebviewmediation-adapter-mopub.aarを追加します。
  2. File -> Project Structure -> app -> Dependencies よりmopub-sdk,androidwebviewmediation-adapter-mopubを追加します。

gradleの設定

手動でSDKを追加した場合、app/build.gradleに以下の行を追加します。

android {
        
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
  ...
  jcenter()
}

dependencies {
  ...

  // com.android.support配下のライブラリのバージョンはプロジェクト内で同一バージョンを指定する必要があります
  // implementation 'com.mopub.volley:mopub-volley:2.0.0' // adstir sdk 2.11.4 以降
  implementation 'com.mopub.volley:mopub-volley:2.1.0' // adstir sdk 2.14.1 以降
  
  // implementation 'com.google.android.exoplayer:exoplayer:2.8.2' // adstir sdk 2.13.0以降
  // implementation 'com.google.android.exoplayer:exoplayer:2.8.3' // adstir sdk 2.13.4以降
  implementation 'com.google.android.exoplayer:exoplayer:2.9.5' // adstir sdk 2.14.1以降

  // implementation 'com.android.support:recyclerview-v7:27.x.x' // adstir sdk 2.13.0以降
  implementation "androidx.legacy:legacy-support-v4:1.0.0" // adstir SDK 2.14.6以上
  implementation "androidx.annotation:annotation:1.1.0" // adstir SDK 2.14.6以上
  implementation "androidx.recyclerview:recyclerview:1.1.0" // adstir SDK 2.14.6以上
  implementation "androidx.appcompat:appcompat:1.1.0" // adstir SDK 2.14.6以上

}

ProGuardの設定

ProGuardを使用しているアプリにはproguard-rules.proに、下記の内容を追加してください。
この記述が無い場合、adstirの機能を正常に利用することができません。

# Keep public classes and methods.
-keepclassmembers class com.mopub.** { public *; }
-keep public class com.mopub.**
-keep public class android.webkit.JavascriptInterface {}

# Explicitly keep any custom event classes in any package.
-keep class * extends com.mopub.mobileads.CustomEventBanner {}
-keep class * extends com.mopub.mobileads.CustomEventInterstitial {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}
-keep class * extends com.mopub.nativeads.CustomEventRewardedAd {}

# Keep methods that are accessed via reflection
-keepclassmembers class ** { @com.mopub.common.util.ReflectionTarget *; }

# Support for Android Advertiser ID.
-keep class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {*;}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {*;}

# Support for Google Play Services
# http://developer.android.com/google/play-services/setup.html
-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;
}