10

在我的 Admob 中,我为 Flurry 和 Vungle 设置了中介。当我请求广告时,我总是收到 Logcat 中提供的错误。

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

代码参考

摇篮

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 设置

我已经在 Admob 中设置了 adunit,其中 Adtype 为 Interstitial,如下所示在此处输入图像描述

代码

@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()");

        }
    });
}

日志猫:

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
4

1 回答 1

6

该程序正在寻找 MediationRewardedVideoAdAdapter 的实现,是实现MediationAdapter的 ad.rewards.meditation 的接口。

您正在使用:

com.vungle.mediation.VungleInterstitialAdapter

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

你的班:

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

我不确定您在调用的其他方法中在哪里实现适配器,但您说您也有 Interstitial 工作。使用 vungle 和 flurry 之间似乎有些混淆。根据vungle 文档

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

您同时使用这两种方法,并且需要说明您在每个 AdRequest 中使用的是哪一种。

您可以像这样初始化 AdView:

 AdView admobView = new AdView(this);

代替:

AdView admobView = createAdView();

您可以在创建 AdRequest.Builder 后将其添加到您的行中以运行测试。

AdRequest.Builder.addTestDevice("B6155B00A6A175A4D29AE13C0F0FBD7B");

还要检查你是否为 Flurry 设置了 api 密钥。这包含一些信息,用于使用 AdMob、在仪表板中以及在 Android 上通过 AdMob 进行调解的代码中设置 Flurry 适配器

它还显示了一个关于添加适配器附加功能的有趣代码片段:

FlurryAdapterExtras flurryAdapterExtras = new FlurryAdapterExtras();

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

部分回答空指针异常的原始问题。

在 onPause、onResume 和 onDestroy 方法中进行空检查。将初始化放在 onCreate 中可能是明智的,而不是将其放在单独的方法中。

在初始化之前,您的 onPause 方法可能由于某种原因rewardedVideoAd被调用。至少通过这种方式,您会感觉到它是否会运行,并且应该会消除该错误(尽管可能会提供一个新错误)。

将以下所有方法放在您的 oncreate 方法之后,以提高可读性。

@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();
}
于 2016-01-31T13:18:43.333 回答