Search Unity

Help: Game crashing when opening in android

Discussion in 'Editor & General Support' started by jameslol417, May 19, 2019.

  1. jameslol417

    jameslol417

    Joined:
    Jan 18, 2019
    Posts:
    7
    It's my first time making a game with unity and to put ads in my game i followed youtube and wrote down the following code. In the Unity editor after build the message like below pops up and after importing to phone it just crashes... Any help?


    Code (CSharp):
    1. using GoogleMobileAds.Api;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class AdScript : MonoBehaviour {
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.  
    11.         showBannerAd();
    12.        
    13.     }
    14.  
    15.     private void showBannerAd()
    16.     {
    17.         string adID = "ca-app-pub-3940256099942544/6300978111";
    18.  
    19.         //***For Testing in the Device***
    20.         AdRequest request = new AdRequest.Builder()
    21.        .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
    22.        .AddTestDevice("2077ef9a63d2b398840261c8221a0c9b")  // My test device.
    23.        .Build();
    24.  
    25.         //***For Production When Submit App***
    26.         //AdRequest request = new AdRequest.Builder().Build();
    27.  
    28.         BannerView bannerAd = new BannerView(adID, AdSize.SmartBanner, AdPosition.Top);
    29.         bannerAd.LoadAd(request);
    30.     }
    31.  
    32.     // Update is called once per frame
    33.     void Update () {
    34.        
    35.     }
    36. }
     

    Attached Files:

  2. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    107
    I think you are missing the appID.
    Code (CSharp):
    1. ...
    2. using GoogleMobileAds.Api;
    3. ...
    4. public class GoogleMobileAdsDemoScript : MonoBehaviour
    5. {
    6.     public void Start()
    7.     {
    8.         #if UNITY_ANDROID
    9.             string appId = "ca-app-pub-3940256099942544~3347511713";
    10.         #elif UNITY_IPHONE
    11.             string appId = "ca-app-pub-3940256099942544~1458002511";
    12.         #else
    13.             string appId = "unexpected_platform";
    14.         #endif
    15.  
    16.         // Initialize the Google Mobile Ads SDK.
    17.         MobileAds.Initialize(appId);
    18.     }
    19. }
    https://developers.google.com/admob/unity/start