• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android [SOLVED] AdMob is crashing my game on Android

Dan1

Member
Hey everyone,

I hope you can help here. I'm having some real trouble setting up AdMob to work on android.
When I play the game on PC it works fine (without ads), but when I export the APK and run on my android device, whenever I enter the level (where I want to display the ad), it crashes the game.

What I want to achieve is a banner ad in-game and an interstitial ad when exiting to go back to the menu.

This is my code at the moment:

Level Control Object <CREATE>
Code:
if(os_type==os_android)
{
GoogleMobileAds_LoadInterstitial();
GoogleMobileAds_AddBannerAt("---BANNER AD ID PLACED HERE---",GoogleMobileAds_Banner,0,0)
}
Level Control Object <SOCIAL>
Code:
var _id = async_load[? "id"];
if _id == GoogleMobileAds_ASyncEvent
{
var ident = async_load[? "type"];
switch (ident)
    {
    case "banner_load":
        if async_load[? "loaded"] == 1
            {
GoogleMobileAds_MoveBanner(((abs(display_get_width()-GoogleMobileAds_BannerGetWidth()))/2)+100, 0);
            }
        break;
    }
}
Back to Menu <CREATE>
Code:
interstitial_loaded = false
Back to Menu <STEP>
Code:
    if GoogleMobileAds_InterstitialStatus() == "Ready"
        {
        if interstitial_loaded != true
            {
            interstitial_loaded = true;
            }
        }
Back to Menu Button <LEFT RELEASED>
Code:
if interstitial_loaded = true
    {
    interstitial_loaded = false;
    GoogleMobileAds_ShowInterstitial();
    }
Level Select Controller (Room before Control Object) <CREATE>
Code:
if(os_type==os_android)
{
GoogleMobileAds_Init("---INTERSTITIAL AD ID PLACED HERE---")
}
My understanding of this is that it would set up the ads before I load the level, then when the level is loaded, it will display them. However, it just crashes out of the game entirely with no explanation!

Any ideas what I'm doing wrong here, any help is really appreciated.

Thanks :)
 

chirpy

Member
Try use adb logcat to capture detailed logs; if the game compiles your gml code should be fine.
 

Dan1

Member
Try use adb logcat to capture detailed logs; if the game compiles your gml code should be fine.
The problem is, it does compile successfully and the game runs right up until I try to call an ad through AdMob.
When I try to do that, it just crashes out of the game suddenly.
I've tried making a project file with JUST the AdMob code and the exact same thing happens.
I think it might be a problem with GMS 2 since they haven't focused much on AdMob since GMS 1.4, I've asked the support people for help but so far they're directing it back to me saying it's a fault on my end, not a fault with GMS 2.
I'm at my wits end, I just want it to work!
 
Finally after 2 days inside google play extension changing all java codes and creating extensions withouth any results, i changed game maker version to 2.1.5.322 and
it WORKS! so i recommend to change your version, if you want to use 2.1.5.322 and you get a fatal error saying something about manifest aplication just get inside
the 2.1.5 runtime search for manifest and inside change this ${YYAndroidTVBanner} with this android:banner="@drawable/banner"
 

Dan1

Member
I tried this and sadly still nothing :(
I changed the runtime to 2.1.5.276 and still got the same result - open the room that requests the ad and suddenly crashes and closes apk.
I'm not entirely advanced enough to dive in to the java codes so I'm not sure what else to try here?
 

pipebkOT

Member
@Dan1

where do you wanna put the ads? in the level select room, or in the level room?

You didn't init the banner ad, it should be like this

Level Select Controller (Room before Control Object) <CREATE>

Code:
if(os_type==os_android)
{
GoogleMobileAds_Init("---INTERSTITIAL AD ID PLACED HERE---")
GoogleMobileAds_Init("---BANNER AD ID PLACED HERE---")
}
 

Dan1

Member
@Dan1

where do you wanna put the ads? in the level select room, or in the level room?

You didn't init the banner ad, it should be like this

Level Select Controller (Room before Control Object) <CREATE>

Code:
if(os_type==os_android)
{
GoogleMobileAds_Init("---INTERSTITIAL AD ID PLACED HERE---")
GoogleMobileAds_Init("---BANNER AD ID PLACED HERE---")
}
In the Control Object, I'd used:
Code:
GoogleMobileAds_AddBannerAt("ca-app-pub-7356342087875399/4859142845",GoogleMobileAds_Banner,0,0)
to load the banner ad and loaded the interstitial in the room before - however, I've tried it again loading both and again had the same issue!

I'm trying to load the ads only in the main level room and load the interstitial to show in the same room before going back to the level select

However, this might help, this is just the ad portion of what I'm trying to do as a YYZ:
http://www.filedropper.com/adtest
 

pipebkOT

Member
@Dan1 , i'm gonna check it


Final edit: @Dan1

it seems like you forget to fill the funtion with the aplication iD provided by admob, also, you need to load the insterestial immediately after the init otherwise the funtion GoogleMobileAds_LoadInterstitial() will not work, so the code is this:

Level Select controller<CREATE>

Code:
if(os_type==os_android)
{
GoogleMobileAds_Init("ca-app-pub-7356342087875399/4859142845","insert app id")//interestial?
GoogleMobileAds_LoadInterstitial()
GoogleMobileAds_Init("ca-app-pub-7356342087875399/4454930117","insert app id")


}
Level Control Object <CREATE>
Code:
if(os_type==os_android)
{
GoogleMobileAds_AddBannerAt("---BANNER AD ID PLACED HERE---",GoogleMobileAds_Banner,0,0)
}
BACK TO MENU BUTTON <left click released

Code:
if os_is_network_connected()//checks if is connected to internet
{
if GoogleMobileAds_InterstitialStatus() == "Ready"
{
GoogleMobileAds_ShowInterstitial();
}
else
{
room_goto(desired room)//if is  not connected to internet then goes to the room without loading the ad
}
Back to Menu button <social async event>
Code:
var _id = async_load[? "id"];
    if _id == GoogleMobileAds_ASyncEvent
    {
    var ident = async_load[? "type"];
    switch (ident)
        {
       case "interstitial_closed":  ///checked that the interstitial was viewed and closed
    GoogleMobileAds_LoadInterstitial();
 room_goto(back to the level select room)
    break;
 
        }
    }

I tested the your adtest proyect with test ads from admob an it worked fine with de code I provide you, so now try using this code and tell me if it works with your ads.

also, try using the test ads first if you want https://developers.google.com/admob/android/test-ads?hl=en (as these test ads doesn't require app id's to work )
 
Last edited:
Top