Search Unity

Random crashes caused by Ads on Android

Discussion in 'Android' started by Deleted User, Jan 22, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hi, just wondering if anyone can provide any insight or workarounds here (hopefully I've posted this in an appropriate category - there didn't seem any others that would be relevant). I've recently included ads into my Android game, which is live on the Play Store. Before implementing ads it had zero crashes (and did have users so was running on plenty devices). I started with Unity Ads, but found that this was causing occasional crashes on various devices. So, I changed to AdMob, and am finding the same issue, although AdMob is generating slightly less crashes overall. The crash reports are always along the lines of 'java.lang.Error in $Proxy9.onAdLoaded' or something similar. I have followed implementation guidelines for each of them very carefully, at least to the best of my knowledge. It appears to me that the game / ads plugin is sending a request for an ad, then when the response comes back the listener to handle it is no longer there, hence the crash. Maybe this is to do with user closing the app at an inconvenient moment, whereby the listeners are getting removed by the ad object as it ends its own thread, and the response from the server is coming in at that point in time, so maybe the code is trying to invoke a listener it has just got rid of. Or maybe it is nothing at all to do with this type of scenario. Anyway, I'm interested to see if anyone else gets the same kinds of crash reports, and if there's anything that can be done about it, or if I'm just being an idiot and have missed something glaringly obvious.
     
  2. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    254
    I was experiencing frequent crash due to AdMob on android and it was related to Android API Level version, if you are using the official AdMob plugin from here: (https://github.com/googleads/googleads-mobile-unity) and the latest version v3.15.0, then I would suggest update your to Android API Level version to greater than 26, latest is 28 I think. So update it to Level 28 using Android Studio.
     
  3. Deleted User

    Deleted User

    Guest

    Thanks for advice. Already mostly doing all of what you recommend though, API level 28, export and build with Android Studio, only difference is AdMob plugin v3.15.1. Might see if downgrade to v3.15.0 improves stability.
     
  4. Deleted User

    Deleted User

    Guest

    OK, so finally getting somewhere with this. The issue appears to be related to the game resuming after a user has clicked an ad, and therefore navigated away, but has then returned to the game (via back button?). In such a situation, the ads system seems to be sometimes reverting to either an uninitialized state (or at the very least has lost references to the callback handlers), but the game itself thinks everything is back up and running as before - meaning when a callback is triggered, it isn't there, so the app crashes. I'm fairly new to Unity, having previously written native code for Android, so it might be my set up or something. However, the Unity/Monobehaviour lifecycle is much simpler then an actual Android lifecycle. In native Android code I would write lots of checks and balances at every lifecycle state change, and would keep on top of things like this (btw I'm not wanting to go back to this!). The Unity ads plugins are very straightforward in terms of initializing / requesting ads / and showing them to users. However nothing much is exposed in terms of dropping the lifecycle state of the ads back down when the app pauses or stops. I have used a bit of a 'sledgehammer to crack a nut' solution for the time being - whenever the AdLeavingApp() callback is invoked I'm calling Application.Quit(). This has stopped the crashes, but is somewhat less than ideal since users will have to go through a full launch to get back into the game (not quite as bad as it could be since all ads are on the intro scene). It may be that I can just set a flag to force re-initialize of ads upon resuming rather than stop the app altogether, but I need to run a few tests to see whether this is going to work. This situation appears to be the case for both AdMob and Unity Ads as far as I can see.
     
  5. ARPAplus

    ARPAplus

    Joined:
    Jun 5, 2015
    Posts:
    32
    We've got same problem. Updated apps with latest Unity 2018.3.6f1 (+ Admob plugin v3.15.1) and got huge crash spikes which crossed red line of "bad behaviour" metrics in Android Vital. So many crashes of $Proxy9.onAdLoaded and similar.

    Rebuilding with old Unity 2018.2 helped, but this is bad workaround as long as there is no AAB. Some of our project already built with 2018.3 and this new prefab system so it can't be reverted back to 2018.2 and we live with crashes.
     
  6. IceCatGames

    IceCatGames

    Joined:
    Mar 22, 2016
    Posts:
    33
  7. Deleted User

    Deleted User

    Guest