AdMob Rewarded Ads crashing on my Android Emulator

My main activity:

    //init ads & load
    MobileAds.initialize(getApplicationContext(), new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
            //on initalized
        }
    });

loadRewardedAd()

    private void loadRewardedAd() {
    RewardedAd.load(getApplicationContext(), ADS_REWARDED_ID, new AdRequest.Builder().build(), new RewardedAdLoadCallback() {
        @Override
        public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
            super.onAdLoaded(rewardedAd);

            //loaded
            adsRewarded = rewardedAd;

            //listener
            adsRewarded.setFullScreenContentCallback(new FullScreenContentCallback() {
                @Override
                public void onAdFailedToShowFullScreenContent(AdError adError) {
                    super.onAdFailedToShowFullScreenContent(adError);

                    //failed
                    adsRewarded = null;
                    loadRewardedAd();
                }

                @Override
                public void onAdShowedFullScreenContent() {
                    super.onAdShowedFullScreenContent();

                    //showed
                    adsRewarded = null;
                    loadRewardedAd();
                }

                @Override
                public void onAdDismissedFullScreenContent() {
                    super.onAdDismissedFullScreenContent();

                    //dismissed
                }
            });
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            super.onAdFailedToLoad(loadAdError);

            //failed
            adsRewarded = null;
        }
    });
}

Sometimes when onAdLoaded() runs, it crashes immediately. But this only happens on my Android Emulator. Although my phone is Android 10 (same as emulator) I did not see any crashes. I don’t get any warning, logcat just gives memory leak warning.

Crash log:

https://paste.ubuntu.com/p/5WPZhkTknp/

Answer

I’ve solved the crash problem. It happens only in admob 19.7.0 version and debug mode.

So I changed my build:gradle like this:

buildTypes {
    debug {
        debuggable false //false when testing admob 19.7.x
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *