Rewarded Video Ad in Admob - Mediation not Working

iappmaker picture iappmaker · Jan 28, 2016 · Viewed 10.4k times · Source

From my Admob, I have setup the mediation for Flurry and Vungle. When I request an Ad I am always getting the error as provided in the Logcat.

Could not instantiate mediation adapter: com.google.ads.mediation.flurry.FlurryAdapter.
MediationAdapter is not a MediationRewardedVideoAdAdapter: com.vungle.mediation.VungleInterstitialAdapter

Code Reference

Gradle

dependencies {

compile files('libs/FlurryAnalytics-6.2.0.jar')
compile files('libs/FlurryAds-6.2.0.jar')
compile files('libs/flurryAndroidDFPandAdMobMediationAdapter-5.0.0.r1.jar')
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/vungle-publisher-adaptive-id-3.3.4.jar')
compile files('libs/VungleAdapter.jar')

compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services-ads:8.3.+'
compile 'com.google.android.gms:play-services-analytics:8.3.+'
compile 'com.google.android.gms:play-services-appindexing:8.3.+'
compile 'com.google.android.gms:play-services-appinvite:8.3.+'
compile 'com.google.android.gms:play-services-games:8.3.+'
compile 'com.google.android.gms:play-services-identity:8.3.+'
compile 'com.google.android.gms:play-services-plus:8.3.+'
compile project(':BaseGameUtils')
compile project(':facebook-android-sdk-4.8.1')
compile files('libs/AudienceNetwork.jar')
compile files('libs/FacebookAdapter.jar')
}

Admob Setup

I have setup the adunit in Admob with the Adtype as Interstitial like shown belowenter image description here

Code

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
@Override
protected void onPause() {
    super.onPause();
    if(rewardedVideoAd!= null)
        rewardedVideoAd.pause();
    socialShareType=null;
}
@Override
protected void onResume() {
    super.onResume();
    if(rewardedVideoAd!=null)
        rewardedVideoAd.resume();
    // Refresh the state of the +1 button each time we receive focus.
    if(canShowGPlus1() && plusOneButton!=null) {
        plusOneButton.initialize("https://developers.google.com/+", PLUS_ONE_REQUEST_CODE);
    //  plusOneButton.initialize("https://play.google.com/store/apps/details?id=com.game.puzzle.game.ballmania.android", PLUS_ONE_REQUEST_CODE);
    }
}
@Override
public void onDestroy() {
    if(rewardedVideoAd!=null)
        rewardedVideoAd.destroy();
    super.onDestroy();
    accessTokenTracker.stopTracking();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    rateMe();
    getActualScreenSize();

    // Initialize the SDK before executing any other operations,
    // especially, if you're using Facebook UI elements.
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    shareDialog = new ShareDialog(this);

    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    // App code
                    System.out.println("FacebookCallback : Success");
                    //fbShareNow();
                }

                @Override
                public void onCancel() {
                    // App code
                    System.out.println("FacebookCallback : Cancel");
                }

                @Override
                public void onError(FacebookException exception) {
                    // App code
                    System.out.println("FacebookCallback : Erroe");
                }
            });
    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
            currentAccessToken=newAccessToken;
        }
    };

    currentAccessToken =  AccessToken.getCurrentAccessToken();

    c=AndroidLauncher.this;
    bld = new AlertDialog.Builder(this);

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

    //initialize(new MainGame(this), config);

    // Create the layout
    layout = new RelativeLayout(this);

    // Do the stuff that initialize() would do for you
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    AdView admobView = createAdView();
    layout.addView(admobView);

    View gameView = initializeForView(new MainGame(this), config);
    layout.addView(gameView);

    showGPlus1(150, 150, 150, 150);

    setContentView(layout);

    if (isAppInstalledFromGooglePlay()) {
        iabSetup();
    }else{
        Arrays.fill(gemPurchased, Boolean.FALSE);
    }

    initializeGameServices();

    alarmSetup();


    setInterestial();
    setRewardedVideo();

    //getHash();

}
private void setRewardedVideo() {
    rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
    rewardedVideoAd.setUserId("userId"); 
    AdRequest adRequest = new AdRequest.Builder().build();
    rewardedVideoAd.loadAd(AD_UNIT_ID_REWARDED_VIDEO_AD, adRequest);

    rewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
        @Override
        public void onRewardedVideoAdLoaded() {
            System.out.println("onRewardedVideoAdLoaded()");
            if (rewardedVideoAd.isLoaded()) {
                rewardedVideoAd.show();
            }
        }

        @Override
        public void onRewardedVideoAdOpened() {
            System.out.println("onRewardedVideoAdOpened()");

        }

        @Override
        public void onRewardedVideoStarted() {
            System.out.println("onRewardedVideoStarted()");

        }

        @Override
        public void onRewardedVideoAdClosed() {
            System.out.println("onRewardedVideoAdClosed()");

        }

        @Override
        public void onRewarded(RewardItem rewardItem) {
            System.out.println("onRewarded()");

        }

        @Override
        public void onRewardedVideoAdLeftApplication() {
            System.out.println("onRewardedVideoAdLeftApplication()");

        }

        @Override
        public void onRewardedVideoAdFailedToLoad(int i) {
            System.out.println("onRewardedVideoAdFailedToLoad()");

        }
    });
}

Logcat:

01-31 19:38:05.795    6634-6634/com.game.puzzle.game.ballmania.android I/dalvikvm﹕ Could not find method android.security.NetworkSecurityPolicy.getInstance, referenced from method com.google.android.gms.ads.internal.t.e.a
01-31 19:38:06.085    6634-6735/com.game.puzzle.game.ballmania.android D/dalvikvm﹕ DexOpt: --- BEGIN 'ads1706048048.jar' (bootstrap=0) ---
01-31 19:38:06.285    6634-6735/com.game.puzzle.game.ballmania.android D/dalvikvm﹕ DexOpt: --- END 'ads1706048048.jar' (success) ---
01-31 19:38:06.285    6634-6735/com.game.puzzle.game.ballmania.android D/dalvikvm﹕ DEX prep '/data/data/com.game.puzzle.game.ballmania.android/cache/ads1706048048.jar': unzip in 0ms, rewrite 207ms
01-31 19:38:13.165    6634-6634/com.game.puzzle.game.ballmania.android I/Ads﹕ Starting ad request.
01-31 19:38:13.175    6634-6634/com.game.puzzle.game.ballmania.android I/Ads﹕ Use AdRequest.Builder.addTestDevice("B6155B00A6A175A4D29AE13C0F0FBD7B") to get test ads on this device.
01-31 19:38:16.665    6634-7074/com.game.puzzle.game.ballmania.android W/Ads﹕ Could not instantiate mediation adapter: com.google.ads.mediation.flurry.FlurryAdapter. null
01-31 19:38:16.715    6634-7074/com.game.puzzle.game.ballmania.android W/Ads﹕ Fail to instantiate adapter com.google.ads.mediation.flurry.FlurryAdapter
    android.os.RemoteException
            at com.google.android.gms.internal.zzev.zzah(Unknown Source)
            at com.google.android.gms.internal.zzev.zzaf(Unknown Source)
            at com.google.android.gms.internal.zzew$zza.onTransact(Unknown Source)
            at android.os.Binder.transact(Binder.java:347)
            at com.google.android.gms.ads.internal.l.a.d.a(SourceFile:94)
            at com.google.android.gms.ads.internal.reward.c.b(SourceFile:194)
            at com.google.android.gms.ads.internal.reward.mediation.h.a(SourceFile:53)
            at com.google.android.gms.ads.internal.util.b.run(SourceFile:19)
            at com.google.android.gms.ads.internal.util.r.call(SourceFile:52)
            at com.google.android.gms.ads.internal.util.s.run(SourceFile:75)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:841)
01-31 19:38:16.745    6634-7075/com.game.puzzle.game.ballmania.android W/Ads﹕ MediationAdapter is not a MediationRewardedVideoAdAdapter: com.vungle.mediation.VungleInterstitialAdapter
01-31 19:38:16.745    6634-7075/com.game.puzzle.game.ballmania.android W/Ads﹕ Fail to check if adapter is initialized.
    android.os.RemoteException
            at com.google.android.gms.internal.zzfd.isInitialized(Unknown Source)
            at com.google.android.gms.internal.zzex$zza.onTransact(Unknown Source)
            at android.os.Binder.transact(Binder.java:347)
            at com.google.android.gms.ads.internal.l.a.g.g(SourceFile:621)
            at com.google.android.gms.ads.internal.reward.mediation.a.a(SourceFile:83)
            at com.google.android.gms.ads.internal.util.b.run(SourceFile:19)
            at com.google.android.gms.ads.internal.util.r.call(SourceFile:52)
            at com.google.android.gms.ads.internal.util.s.run(SourceFile:75)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:841)
01-31 19:38:16.745    6634-6634/com.game.puzzle.game.ballmania.android W/Ads﹕ Failed to load ad: 3

Answer

user3956566 picture user3956566 · Jan 31, 2016

The program is looking for an implementation of the MediationRewardedVideoAdAdapter which is an interface of the ad.rewards.meditation, which implements MediationAdapter.

You are using:

com.vungle.mediation.VungleInterstitialAdapter

MediationAdapter is not a MediationRewardedVideoAdAdapter: com.vungle.mediation.VungleInterstitialAdapter

Your class:

public class AndroidLauncher extends AndroidApplication 
    implements ActionResolver, GameHelper.GameHelperListener {

I'm not sure where you are implementing your adapters in your other methods that you are calling, but you said you have Interstitial working also. Seems like some confusion between using vungle and flurry. As per the vungle documentation.

compile files('libs/flurryAndroidDFPandAdMobMediationAdapter-5.0.0.r1.jar')
compile files('libs/VungleAdapter.jar')

You are using both and will need to clarify which you are using in each AdRequest.

You can initialise the AdView like so:

 AdView admobView = new AdView(this);

Instead of:

AdView admobView = createAdView();

You can add this to your line after your create AdRequest.Builder to run tests.

AdRequest.Builder.addTestDevice("B6155B00A6A175A4D29AE13C0F0FBD7B");

Also check that your have your api keys set up for flurry. This has some information for to set up a flurry adapter with AdMob, in the dashbooard, and in the code Mediate via AdMob on Android

It also shows an interesting code snippet on adding adapter extras:

FlurryAdapterExtras flurryAdapterExtras = new FlurryAdapterExtras();

AdRequest adRequest = new AdRequest.Builder()
    .addNetworkExtras(flurryAdapterExtras).build();

In part to answer the original question of the null pointer exception.

Put null checks in your onPause, onResume and onDestroy methods. It might be wise to put the initialisation within the onCreate, rather than putting it into a separate method.

It's possible your onPause method is being called for some reason before the rewardedVideoAd has been intialised. At least this way, you will get a feel if it is going to run, and it should remove that error (may provide a new one though).

The place all the following methods after your oncreate method, for readability.

@Override
protected void onPause() {
    if(rewardedVideoAd!=null)
        rewardedVideoAd.pause();
    super.onPause();
    .../...
}
@Override
protected void onResume() {
    super.onResume();
    if(rewardedVideoAd!=null)
        rewardedVideoAd.resume();
    .../...

    }
}
@Override
public void onDestroy() {
    if(rewardedVideoAd!=null)
        rewardedVideoAd.destroy();
    super.onDestroy();
    accessTokenTracker.stopTracking();
}