SDK issues

169 views
Skip to first unread message

diego

unread,
Jun 29, 2023, 10:42:32 PM6/29/23
to Google Mobile Ads SDK Developers
Hello everyone, I have a problem. What happens is that I bought a template of a game in the unity asset store, but that template has not been updated since 2021 and the developer put the ad implementation for the sdk that was recent in that year, which is v6.1.0 for what when importing the most recent version of google mobile ads sdk gives me errors the console, and only leaves with the old version (6.1.0) this is because the google ads sdk implementation mode changed and no longer It is used the same as in version 6.
I will leave the screenshots of the errors attached. If you could tell me what to correct or what to do, I would greatly appreciate it. I don't have much programming knowledge. 

this is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

#if BBG_ADMOB
using GoogleMobileAds.Api;
#endif

namespace BBG.MobileTools
{
    public class AdMobNetworkHandler : AdNetworkHandler
    {
        #region Member Variables

        #if BBG_ADMOB
        private BannerView          bannerView;
        private InterstitialAd      interstitialAd;
        private RewardedAd          rewardedAd;
        private bool                showBannerAd;
        private float               bannerHeight;
        #endif

        #endregion

        #region Properties

        protected override string LogTag { get { return "AdMob"; } }

        private string BannerAdUnitId       { get { return MobileAdsSettings.Instance.adMobConfig.BannerPlacementId; } }
        private string InterstitialAdUnitId { get { return MobileAdsSettings.Instance.adMobConfig.InterstitialPlacementId; } }
        private string RewardAdUnitId       { get { return MobileAdsSettings.Instance.adMobConfig.RewardPlacementId; } }

        #endregion

        #region Protected Methods

        protected override void DoInitialize()
        {
            GameDebugManager.Log(LogTag, "Initializing AdMob");

            #if BBG_ADMOB

            // Initialize AdMob
            MobileAds.Initialize((Status) =>
            {
                isInitialized = true;

                // Set the text device ids
                List<string> testDeviceIds = MobileAdsSettings.Instance.adMobConfig.DeviceTestIds;

                if (testDeviceIds.Count > 0)
                {
                    MobileAds.SetRequestConfiguration(new RequestConfiguration.Builder().SetTestDeviceIds(testDeviceIds).build());
                }

                // Make sure an instance of InvokeOnMainThread is created
                InvokeOnMainThread.CreateInstance();
             
                // If we are using AdMob for banner ads then pre-load one now
                if (bannerAdsEnabled)
                {
                    GameDebugManager.Log(LogTag, "Banner ads enabled, Unit Id: " + BannerAdUnitId);

                    showBannerAd = MobileAdsSettings.Instance.adMobConfig.ShowBannerOnStart;

                    PreLoadBannerAd();
                }

                // If we are using AdMob for interstitial ads then pre-load one now
                if (interstitialAdsEnabled)
                {
                    GameDebugManager.Log(LogTag, "Interstitial ads enabled, Unit Id: " + InterstitialAdUnitId);

                    PreLoadInterstitialAd();
                }

                // If we are using AdMob for reward ads then pre-load one now
                if (rewardAdsEnabled)
                {
                    GameDebugManager.Log(LogTag, "Reward ads enabled, Unit Id: " + RewardAdUnitId);

                    PreLoadRewardAd();
                }
            });

            #else

            GameDebugManager.LogError(LogTag, "AdMob has not been setup in Mobile Ads Settings");

            #endif //BBG_ADMOB
        }

        protected override void DoLoadBannerAd()
        {
            #if BBG_ADMOB
            // Only load a new banner ad if the ad stat is none
            if (BannerAdState == AdState.None)
            {
                CreateBannerAd();
            }
            #endif
        }

        protected override void DoShowBannerAd()
        {
            #if BBG_ADMOB
            showBannerAd = true;

            switch (BannerAdState)
            {
                case AdState.None:
                    CreateBannerAd();
                    break;
                case AdState.Loaded:
                    bannerView.Show();
                    BannerAdState = AdState.Shown;
                    NotifyBannerAdShown();
                    break;
                default:
                    GameDebugManager.Log(LogTag, "DoShowBannerAd: Nothing will happen because BannerAdState is: " + BannerAdState);
                    break;
            }

            #endif
        }

        protected override void DoHideBannerAd()
        {
            #if BBG_ADMOB
            showBannerAd = false;

            if (BannerAdState == AdState.Shown)
            {
                bannerView.Hide();
                BannerAdState = AdState.Loaded;
                NotifyBannerAdHidden();
            }
            else
            {
                GameDebugManager.Log(LogTag, "DoHideBannerAd: Nothing will happen because BannerAdState is: " + BannerAdState);
            }
            #endif
        }

        protected override void DoLoadInterstitialAd()
        {
            #if BBG_ADMOB
            if (interstitialAd != null)
            {
                interstitialAd.Destroy();
                interstitialAd = null;
            }

            interstitialAd = new InterstitialAd(InterstitialAdUnitId);

            interstitialAd.OnAdLoaded       += InterstitialAdLoaded;
            interstitialAd.OnAdFailedToLoad += InterstitialAdFailedToLoad;
            interstitialAd.OnAdOpening      += InterstitialAdOpening;
            interstitialAd.OnAdClosed       += InterstitialAdClosed;

            NotifyInterstitialAdLoading();

            interstitialAd.LoadAd(CreateAdRequestBuilder().Build());
            #endif
        }

        protected override void DoShowInterstitialAd()
        {
            #if BBG_ADMOB
            NotifyInterstitialAdShowing();
            interstitialAd.Show();
            #endif
        }

        protected override void DoLoadRewardAd()
        {
            #if BBG_ADMOB
            if (rewardedAd != null)
            {
                rewardedAd.Destroy();
                rewardedAd = null;
            }

            rewardedAd = new RewardedAd(RewardAdUnitId);

            rewardedAd.OnAdLoaded           += RewardAdLoaded;
            rewardedAd.OnAdFailedToLoad     += RewardAdFailedToLoad;
            rewardedAd.OnUserEarnedReward   += RewardAdRewarded;
            rewardedAd.OnAdOpening          += RewardAdOpening;
            rewardedAd.OnAdClosed           += RewardAdClosed;

            NotifyRewardAdLoading();

            rewardedAd.LoadAd(CreateAdRequestBuilder().Build());
            #endif
        }

        protected override void DoShowRewardAd()
        {
            #if BBG_ADMOB
            NotifyRewardAdShowing();
            rewardedAd.Show();
            #endif
        }

        protected override void DoAdsRemoved(bool dontRemoveRewardAds)
        {
            #if BBG_ADMOB
            if (bannerView != null)
            {
                bannerView.Destroy();
                bannerView = null;
            }

            if (interstitialAd != null)
            {
                interstitialAd.Destroy();
                interstitialAd = null;
            }

            if (rewardAdsEnabled && !dontRemoveRewardAds)
            {
                rewardedAd.Destroy();
                rewardedAd = null;
            }
            #endif
        }

        protected override void ConsentStatusUpdated()
        {
            // Consent status will be set next time an ad loads
        }

        protected override float DoGetBannerHeightInPixels()
        {
            #if BBG_ADMOB //&& !UNITY_EDITOR

            if (bannerHeight == 0)
            {
                if (bannerView != null)
                {
                    bannerHeight = bannerView.GetHeightInPixels();
                }
                else
                {
                    BannerView tempView = new BannerView(BannerAdUnitId, GetBannerAdSize(), AdPosition.Bottom);

                    bannerHeight = tempView.GetHeightInPixels();

                    tempView.Destroy();
                }
            }

            return bannerHeight;

            #else

            return 0f;

            #endif
        }

        protected override MobileAdsSettings.BannerPosition DoGetBannerPosition()
        {
            return MobileAdsSettings.Instance.adMobConfig.BannerPosition;
        }

        #endregion

        #region Private Methods

        #if BBG_ADMOB

        /// <summary>
        /// Creates and loads a new BannerView
        /// </summary>
        private void CreateBannerAd()
        {
            BannerAdState = AdState.Loading;

            NotifyBannerAdLoading();

            bannerView = new BannerView(BannerAdUnitId, GetBannerAdSize(), GetAdMobBannerPosition());
       
            bannerView.OnAdLoaded       += BannerAdLoaded;
            bannerView.OnAdFailedToLoad += BannerAdFailedToLoad;

            bannerView.LoadAd(CreateAdRequestBuilder().Build());
            bannerView.Hide();
        }

        /// <summary>
        /// Gets the AdSize that is set in the settings
        /// </summary>
        private AdSize GetBannerAdSize()
        {
            switch (MobileAdsSettings.Instance.adMobConfig.BannerSize)
            {
                case MobileAdsSettings.AdMobConfig.Config.BannerSize.Banner:
                    return AdSize.Banner;
                case MobileAdsSettings.AdMobConfig.Config.BannerSize.IABBanner:
                    return AdSize.IABBanner;
                case MobileAdsSettings.AdMobConfig.Config.BannerSize.Leaderboard:
                    return AdSize.Leaderboard;
                case MobileAdsSettings.AdMobConfig.Config.BannerSize.MediumRectangle:
                    return AdSize.MediumRectangle;
                case MobileAdsSettings.AdMobConfig.Config.BannerSize.SmartBanner:
                    return AdSize.SmartBanner;
            }

            return AdSize.Banner;
        }

        private AdRequest.Builder CreateAdRequestBuilder()
        {
            AdRequest.Builder request = new AdRequest.Builder();

            if (consentStatus == MobileAdsManager.ConsentType.NonPersonalized)
            {
                request.AddExtra("npa", "1");
            }

            return request;
        }

        private AdPosition GetAdMobBannerPosition()
        {
            // Set the ads position
            switch (MobileAdsManager.Instance.BannerAdHandler.GetBannerPosition())
            {
                case MobileAdsSettings.BannerPosition.Top:
                    return AdPosition.Top;
                case MobileAdsSettings.BannerPosition.TopLeft:
                    return AdPosition.TopLeft;
                case MobileAdsSettings.BannerPosition.TopRight:
                    return AdPosition.TopRight;
                case MobileAdsSettings.BannerPosition.Bottom:
                    return AdPosition.Bottom;
                case MobileAdsSettings.BannerPosition.BottomLeft:
                    return AdPosition.BottomLeft;
                case MobileAdsSettings.BannerPosition.BottomRight:
                    return AdPosition.BottomRight;
            }

            return AdPosition.Bottom;
        }

        #region Banner Ad Events

        private void BannerAdLoaded(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                BannerAdState = AdState.Loaded;
                NotifyBannerAdLoaded();

                if (showBannerAd && preLoadBannerAds)
                {
                    ShowBannerAd();
                }
            });
        }

        private void BannerAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                string message = string.Format("Failed to load banner ad\nCode: {0}\n, Message: {1}\n, Cause: {2}\n, Domain: {3}",
                    e.LoadAdError.GetCode(),
                    e.LoadAdError.GetMessage(),
                    e.LoadAdError.GetCause(),
                    e.LoadAdError.GetDomain());

                bannerView.Destroy();
                bannerView = null;

                if (BannerAdState == AdState.Shown)
                {
                    NotifyBannerAdHidden();
                }

                BannerAdState = AdState.None;

                NotifyBannerAdFailedToLoad(e.LoadAdError.GetMessage());
            });
        }

        #endregion

        #region Interstitial Ad Events

        private void InterstitialAdLoaded(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyInterstitialAdLoaded();
            });
        }

        private void InterstitialAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                string message = string.Format("Failed to load interstital ad\nCode: {0}\n, Message: {1}\n, Cause: {2}\n, Domain: {3}",
                    e.LoadAdError.GetCode(),
                    e.LoadAdError.GetMessage(),
                    e.LoadAdError.GetCause(),
                    e.LoadAdError.GetDomain());

                NotifyInterstitialAdFailedToLoad(e.LoadAdError.GetMessage());
            });
        }

        private void InterstitialAdClosed(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyInterstitialAdClosed();

                PreLoadInterstitialAd();
            });
        }

        private void InterstitialAdOpening(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyInterstitialAdShown();
            });
        }

        #endregion // Interstitial Ad Events

        #region Reward Ad Events

        private void RewardAdLoaded(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyRewardAdLoaded();
            });
        }

        private void RewardAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                string message = string.Format("Failed to load reward ad\nCode: {0}\n, Message: {1}\n, Cause: {2}\n, Domain: {3}",
                    e.LoadAdError.GetCode(),
                    e.LoadAdError.GetMessage(),
                    e.LoadAdError.GetCause(),
                    e.LoadAdError.GetDomain());

                NotifyRewardAdFailedToLoad(e.LoadAdError.GetMessage());
            });
        }

        private void RewardAdOpening(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyRewardAdShown();
            });
        }

        private void RewardAdClosed(object sender, System.EventArgs e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyRewardAdClosed();

                PreLoadRewardAd();
            });
        }

        private void RewardAdRewarded(object sender, Reward e)
        {
            InvokeOnMainThread.Action((object[] obj) =>
            {
                NotifyRewardAdGranted(e.Type, e.Amount);
            });
        }

        #endregion // Reward Ad Events

        #endif

        #endregion
    }
}

WhatsApp Image 2023-06-29 at 7.39.09 PM (1).jpeg
WhatsApp Image 2023-06-29 at 7.39.09 PM (2).jpeg
WhatsApp Image 2023-06-29 at 7.39.09 PM.jpeg
WhatsApp Image 2023-06-29 at 7.39.09 PM (3).jpeg

Mobile Ads SDK Forum Advisor

unread,
Jun 30, 2023, 2:34:56 AM6/30/23
to lamar...@gmail.com, google-adm...@googlegroups.com
Hello Diego,

Thank you for reaching out to us. 

You've mentioned that the asset you bought is still using Google Mobile Ads Unity Plugin v6.1.0. This is most likely the cause of the issue you are encountering as the current version for Google Mobile Ads Unity Plugin is v8.3.0. We recommend updating the implementation by referring to our guide for Unity: https://developers.google.com/admob/unity/quick-start

Feel free to reach out back to us if you have any further concerns or inquiries.
 
This message is in relation to case "ref:_00D1U1174p._5004Q2mq7TY:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


mai mohamed مى محمد

unread,
Jul 1, 2023, 10:24:27 AM7/1/23
to diego, Google Mobile Ads SDK Developers
Kirk Franklin county of San Antonio TX 😂😂😄😂😄😂😂😂😂😂😄you so very much for your time and consideration and I will be in touch with ig ☺️😁☺️😁☺️😁😁☺️☺️☺️☺️☺️☺️☺️☺️


--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/95d8245b-08a4-4004-8087-62898b5712een%40googlegroups.com.

Mobile Ads SDK Forum Advisor

unread,
Jul 3, 2023, 4:38:36 AM7/3/23
to maioy...@gmail.com, google-adm...@googlegroups.com
Hello Mai,

Do you have any concerns or inquiries regarding Mobile Ads SDK implementation? Feel free to share with us and we'd be happy to provide assistance.
 
This message is in relation to case "ref:_00D1U1174p._5004Q2mqcCd:ref"


Thanks,
 
Google Logo Mobile Ads SDK Team


Message has been deleted

diego

unread,
Jul 3, 2023, 4:41:52 AM7/3/23
to Google Mobile Ads SDK Developers
Where can I contact you to help me with the code? and explain better what happens with the code

Mobile Ads SDK Forum Advisor

unread,
Jul 3, 2023, 1:19:28 PM7/3/23
to lamar...@gmail.com, google-adm...@googlegroups.com

Hi Diego,

Thank you for your response.

You can contact us on this thread with regard to your concern. With regard to your concern for implementation, we would suggest to try the latest SDK version (https://github.com/googleads/googleads-mobile-unity/releases/tag/v8.3.0), and our sample app (https://github.com/googleads/googleads-mobile-unity/tree/main/samples) for reference in your implementation. Kindly note that the version 6.1.0 is already deprecated (https://developers.google.com/admob/unity/deprecation#timetable). 

Reply all
Reply to author
Forward
0 new messages