Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

App Crashing When Banner Ad is Displayed

Discussion in 'Unity Ads & User Acquisition' started by shadowhunterX21, May 2, 2019.

  1. shadowhunterX21

    shadowhunterX21

    Joined:
    Mar 3, 2019
    Posts:
    7
    Hi so I am having a strange issue. I have a banner ad that shows up a few seconds after starting the game that I developed. Test ads work just fine, the Unity Ads test ad shows up in the banner after a few seconds the game has started. But I am trying to get production ads to work (real ads), and I have set testMode to false. I have also Forced test mode OFF in the operate dashboard. But when I start the game and when the banner is supposed to show up, the game just closes itself on my Android device. Here are the logs from logcat:

    05-01 21:59:15.238 30169 30188 I Unity : Unity Ads initialized: True
    05-01 21:59:15.238 30169 30188 I Unity : App_Initialize:Start()
    05-01 21:59:15.238 30169 30188 I Unity :
    05-01 21:59:15.238 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-01 21:59:15.238 30169 30188 I Unity :
    05-01 21:59:15.240 30169 30188 I Unity : Unity Ads is supported: True
    05-01 21:59:15.240 30169 30188 I Unity : App_Initialize:Start()
    05-01 21:59:15.240 30169 30188 I Unity :
    05-01 21:59:15.240 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-01 21:59:15.240 30169 30188 I Unity :
    05-01 21:59:15.241 30169 30188 I Unity : Unity Ads is showing: False
    05-01 21:59:15.241 30169 30188 I Unity : App_Initialize:Start()
    05-01 21:59:15.241 30169 30188 I Unity :
    05-01 21:59:15.241 30169 30188 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-01 21:59:15.241 30169 30188 I Unity :
    05-01 21:59:19.429 2591 2611 I ActivityManager: Start proc 30241:com.android.chrome:sandboxed_process0/u0i25 for webview_service com.NoCompany.BalloonBeachRun/org.chromium.content.app.SandboxedProcessService0
    05-01 21:59:20.338 2591 3670 I ActivityManager: Process com.android.chrome:sandboxed_process0 (pid 30241) has died: fore TOP
    05-01 21:59:20.339 2591 3670 W ActivityManager: Scheduling restart of crashed service com.NoCompany.BalloonBeachRun/org.chromium.content.app.SandboxedProcessService0 in 1000ms
    05-01 21:59:20.358 2591 3567 I ActivityManager: Process com.NoCompany.BalloonBeachRun (pid 30169) has died: fore TOP
    05-01 21:59:20.359 2591 3567 W ActivityManager: Force removing ActivityRecord{83cbcfb u0 com.NoCompany.BalloonBeachRun/com.unity3d.player.UnityPlayerActivity t20745}: app died, no saved state
    05-01 21:59:20.386 2591 2664 W ActivityManager: setHasOverlayUi called on unknown pid: 30169

    My ads code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.Advertisements;
    using UnityEngine.UI;



    public class App_Initialize : MonoBehaviour
    {
    public GameObject inMenuUI;
    public GameObject inGameUI;
    public GameObject gameOverUI;
    public GameObject player;
    public GameObject adButton;
    public GameObject restartButton;
    private bool hasGameStarted = false;
    private bool hasSeenRewardedAd = false;



    #if UNITY_IOS
    public const string gameID = "3064768";
    #elif UNITY_ANDROID
    public const string gameID = "3064760";
    #elif UNITY_EDITOR
    public const string gameID = "1111111";
    #endif
    public string bannerPlacement = "banner";
    public bool testMode = false;
    public bool show = false;
    void Awake()
    {
    Shader.SetGlobalFloat("_Curvature", 2.0f);
    Shader.SetGlobalFloat("_Trimming", 0.1f);
    Application.targetFrameRate = 60;
    }
    // Start is called before the first frame update
    void Start()
    {
    // show = false;
    // Debug.Log("Unity Ads test mode enabled: " + Advertisement.testMode);

    Advertisement.Initialize(gameID);
    Debug.Log("Unity Ads initialized: " + Advertisement.isInitialized);
    Debug.Log("Unity Ads is supported: " + Advertisement.isSupported);
    Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);
    StartCoroutine(ShowBannerWhenReady());
    player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
    inMenuUI.gameObject.SetActive(true);
    inGameUI.gameObject.SetActive(false);
    gameOverUI.gameObject.SetActive(false);




    }

    public void PlayButton ()
    {
    if(hasGameStarted == true)
    {
    StartCoroutine(StartGame(1.0f));
    }
    else
    {
    StartCoroutine(StartGame(0.0f));
    }

    }

    public void PauseGame ()
    {
    player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
    hasGameStarted = true;
    inMenuUI.gameObject.SetActive(true);
    inGameUI.gameObject.SetActive(false);
    gameOverUI.gameObject.SetActive(false);
    }

    public void GameOver ()
    {
    player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
    hasGameStarted = true;
    inMenuUI.gameObject.SetActive(false);
    inGameUI.gameObject.SetActive(false);
    gameOverUI.gameObject.SetActive(true);
    if(hasSeenRewardedAd == true)
    {
    adButton.GetComponent<Image>().color = new Color(1, 1, 1, 0.5f);
    adButton.GetComponent<Button>().enabled = false;
    adButton.GetComponent<Animator>().enabled = false;
    restartButton.GetComponent<Animator>().enabled = true;
    }
    }

    public void RestartGame ()
    {
    Debug.Log("restart");
    SceneManager.LoadScene(0);
    }

    public void ShowAd ()
    {
    // hasSeenRewardedAd = true;

    if(show == false)
    {
    StartCoroutine(StartGame(1.5f));
    StartCoroutine(ShowBannerWhenReady());

    }

    show = true;

    Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);
    // if (Advertisement.IsReady("banner"))
    // {
    // var options = new ShowOptions { resultCallback = HandleShowResult };
    // Advertisement.Show("banner", options);
    // }
    Debug.Log("Unity Ads is showing: " + Advertisement.isShowing);

    }

    private void HandleShowResult(ShowResult result)
    {
    switch (result)
    {
    case ShowResult.Finished:
    Debug.Log("The ad was successfully shown.");
    hasSeenRewardedAd = true;
    StartCoroutine(StartGame(1.5f));
    break;
    case ShowResult.Skipped:
    Debug.Log("The ad was skipped before reaching the end.");
    break;
    case ShowResult.Failed:
    Debug.LogError("The ad failed to be shown.");
    break;
    }
    }




    // void Start()
    //{

    //}

    IEnumerator ShowBannerWhenReady()
    {
    while (!Advertisement.IsReady("banner"))
    {
    yield return new WaitForSeconds(0.5f);
    }
    Advertisement.Banner.Show(bannerPlacement);
    // yield return new WaitForSeconds(3.5f);
    // Advertisement.Banner.Hide();

    }



    IEnumerator StartGame(float waitTime)
    {
    inMenuUI.gameObject.SetActive(false);
    inGameUI.gameObject.SetActive(true);
    gameOverUI.gameObject.SetActive(false);
    yield return new WaitForSeconds(waitTime);
    player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
    player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
    }

    }
     

    Attached Files:

  2. unity_akeem

    unity_akeem

    Unity Technologies

    Joined:
    Apr 25, 2019
    Posts:
    20
    Hi there. We tested your script and found that the gameID you provided for Android had a typo. If you change this to the correct id you should be able to load a banner. We were not able to reproduce the crash you described.
     
    shadowhunterX21 likes this.
  3. shadowhunterX21

    shadowhunterX21

    Joined:
    Mar 3, 2019
    Posts:
    7
    Yes sorry I changed that for testing, but even with the correct gameID it still won't work.
    But now I found something.
    So I added this line:

    Advertisement.Banner.Load(bannerPlacement);

    and then the real ad displayed a few times, but after three tries it stopped displaying
    Now the banner won't display at all
    in the log now I get a new error:

    05-02 16:41:10.924 14925 14941 I Unity : Unity Ads initialized: True
    05-02 16:41:10.924 14925 14941 I Unity : App_Initialize:Start()
    05-02 16:41:10.924 14925 14941 I Unity :
    05-02 16:41:10.924 14925 14941 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-02 16:41:10.924 14925 14941 I Unity :
    05-02 16:41:10.929 14925 14941 I Unity : Unity Ads is supported: True
    05-02 16:41:10.929 14925 14941 I Unity : App_Initialize:Start()
    05-02 16:41:10.929 14925 14941 I Unity :
    05-02 16:41:10.929 14925 14941 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-02 16:41:10.929 14925 14941 I Unity :
    05-02 16:41:10.935 14925 14941 I Unity : Unity Ads is showing: False
    05-02 16:41:10.935 14925 14941 I Unity : App_Initialize:Start()
    05-02 16:41:10.935 14925 14941 I Unity :
    05-02 16:41:10.935 14925 14941 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-02 16:41:10.935 14925 14941 I Unity :
    05-02 16:41:10.942 14925 14941 I Unity : Unity Ads is showing: False
    05-02 16:41:10.942 14925 14941 I Unity : App_Initialize:Start()
    05-02 16:41:10.942 14925 14941 I Unity :
    05-02 16:41:10.942 14925 14941 I Unity : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    05-02 16:41:10.942 14925 14941 I Unity :
    05-02 16:41:17.360 2605 4392 I ActivityManager: Start proc 14993:com.android.chrome:sandboxed_process0/u0i115 for webview_service com.NoCompany.BalloonBeachRun/org.chromium.content.app.SandboxedProcessService0
    05-02 16:41:19.047 14925 14925 E Unity : TypeLoadException: Could not load type 'UnityEngine.Purchasing.Promo' from assembly 'Stores, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
    05-02 16:41:19.047 14925 14925 E Unity : at System.Type.GetType (System.String typeName, System.Boolean throwOnError, System.Boolean ignoreCase) [0x00000] in <00000000000000000000000000000000>:0
    05-02 16:41:19.047 14925 14925 E Unity : at System.Type.GetType (System.String typeName, System.Boolean throwOnError) [0x00000] in <00000000000000000000000000000000>:0
    05-02 16:41:19.047 14925 14925 E Unity : at UnityEngine.Advertisements.Purchasing.Initialize (UnityEngine.Advertisements.IPurchasingEventSender platform) [0x00000] in <00000000000000000000000000000000>:0
    05-02 16:41:19.047 14925 14925 E Unity : at UnityEngine.Advertisements.Purchase.onInitializePurchasing () [0x00000] in <00000000000000000000000000000000>:0
    05-02 16:41:19.047 14925 14925 E Unity : at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0
    05-02 16:41:19.047 14925 14925 E Unity : at UnityEngine.AndroidJavaProxy.Invoke (Sys
     
  4. unity_akeem

    unity_akeem

    Unity Technologies

    Joined:
    Apr 25, 2019
    Posts:
    20
    Hi there, sorry to hear you're still getting errors. Which version of ads sdk are you using? And how did you install it?
     
    shadowhunterX21 likes this.
  5. shadowhunterX21

    shadowhunterX21

    Joined:
    Mar 3, 2019
    Posts:
    7
    I believe it is verison 3.0.3. It was already installed when I installed Unity. I also uninstalled it and reinstalled it through the package manager in Unity editor.
     
  6. unity_akeem

    unity_akeem

    Unity Technologies

    Joined:
    Apr 25, 2019
    Posts:
    20
    I see. Are you using the Unity IAP SDK? Also, are you using Unity IAP Promo? And which version of Unity are you using? The code you shared doesn't have any references to IAP. Can you share the latest version of your code and the scripts referencing IAP?