game crashes when calling RequestBanner() AdMob
Hello!
I'm making a 2d game in unity and I want to have AdMob banner in my game. So I did everything like it says here: https://developers.google.com/admob/android/games , when I try to run game in Unity Editor it's not showing ads, but everything else is working even log says: Created Dummy Client, Dummy CreateBannerView, Dummy LoadAd (so i guess ads are working) but when i run the game on phone game crashes right after calling RequestBanner() i'm guessing it crashes on bannerView.LoadAd(request);
Here's my RequestBanner function: private void RequestBanner() { // Create a 320x50 banner at the top of the screen. bannerView = new BannerView("ca-app-pub-2895386526091671/9071811144", AdSize.Banner, AdPosition.Top); // Create an empty ad request. request = new AdRequest.Builder().Build(); // Load the banner with the request. bannerView.LoadAd(request); }
I tried many thing but nothing is working for me so please help me.
Answer by GameEverything · Sep 16, 2016 at 08:41 AM
I had this issue for a bit where it was off and on with the AdMob ads and my ads were running on Awake, so I consolidated all of the ad code into an IEnumator ShowBanner function and then added a yield statement with 5 seconds as a parameter before the AdMob code.
I wonder if this is what science is because I totally didn't expect this solution to work, lol.
To wrap up, if you're running your code on Awake or on Start right when you first run your game, try adding some time in between the calling of the function and initialization. My guess is that there was stuff loading at the same time as AdMob that AdMob needs which causes it to crash.
Anyhoo, good luck.
Answer by VirtualCastle · Apr 21, 2016 at 11:08 PM
I'm having the same problem... @pir4t94,I'm having the same problem...
Answer by daothang · Sep 16, 2016 at 02:54 PM
Fix Admob with unity 5 :https://www.youtube.com/watch?v=A8-VCYNByls
Your answer
![](https://koobas.hobune.stream/wayback/20220612061601im_/https://answers.unity.com/themes/thub/images/avi.jpg)