Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Implementing Admob

Discussion in 'Scripting' started by Funzo247, Apr 16, 2020.

  1. Funzo247

    Funzo247

    Joined:
    Apr 16, 2020
    Posts:
    5
    Hello, I'm fairly new to Unity, but I made my own app and I'm just trying to implement ads from admob. The guide on admob is a little difficult to follow, I tried it but couldn't get it working, so I followed tutorials online, to no avail.
    This is my code, with appID removed to protect privacy :p
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5.  
    6. public class Ads : MonoBehaviour
    7. {
    8.     private BannerView bannerView;
    9.  
    10.  
    11.     [SerializeField] private string appID = "";
    12.  
    13.     [SerializeField] private string bannerID = "ca-app-pub-3940256099942544/6300978111";
    14.  
    15.     public void start()
    16.     {
    17.         MobileAds.Initialize(appID);
    18.     }
    19.  
    20.  
    21.        public void ClickAd()
    22.     {
    23.         this.RequestBanner();
    24.     }
    25.  
    26.         private void RequestBanner()
    27.     {
    28.         bannerView = new BannerView(bannerID, AdSize.Banner, AdPosition.Top);
    29.         AdRequest adRequest = new AdRequest.Builder().Build();
    30.         bannerView.LoadAd(adRequest);
    31.     }
    32.  
    33. }
    I have it linked to a button with the function set as ClickAd() but nothing happens. The Console says, "Dummy ctor", "Dummy CreateBannerView", "Dummy LoadAd". What am I doing wrong?

    Edit: Also, just to be sure, I have downloaded the plugin, and have followed everything from https://developers.google.com/admob/unity/start
     
    Last edited: Apr 16, 2020
  2. VSMGames

    VSMGames

    Joined:
    Jan 12, 2020
    Posts:
    47
    Have you tested it on your Android device? Ads are not shown in the editor if you are expecting that to happen.
     
  3. Funzo247

    Funzo247

    Joined:
    Apr 16, 2020
    Posts:
    5
    I thought that might be the case, so I exported it and tested it on my android, they still don't display :(
     
  4. Funzo247

    Funzo247

    Joined:
    Apr 16, 2020
    Posts:
    5
  5. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    596
    Easier to debug when you use the android logger with the device plugged into your computer.
    Otherwise hard to tell what the issue is.
     
  6. Funzo247

    Funzo247

    Joined:
    Apr 16, 2020
    Posts:
    5
    Sorry, I'm quite new to developing apps, how would I got about this? I did some research and I guess it's done in Android Studio, right? Do I need to import my apk to Android Studio?

    Edit: I have logcat and everything brought up, it just says no debuggable processes
     
  7. Funzo247

    Funzo247

    Joined:
    Apr 16, 2020
    Posts:
    5
    Nevermind, I think I got the error. Can't determine the cause of it though.
    Code (JavaScript):
    1. 2020-04-17 15:53:19.870 1846-17823/? E/Ads: Error waiting for future.
    2.     java.util.concurrent.TimeoutException
    3.         at java.util.concurrent.FutureTask.get(FutureTask.java:177)
    4.         at com.google.android.gms.ads.internal.util.future.f.a(:com.google.android.gms@200914021@20.09.14 (040408-300565878):4)
    5.         at com.google.android.gms.ads.cache.k.a(:com.google.android.gms@200914021@20.09.14 (040408-300565878):3)
    6.         at com.google.android.gms.ads.nonagon.signals.gmscore.u.call(:com.google.android.gms@200914021@20.09.14 (040408-300565878):0)
    7.         at bqal.b(:com.google.android.gms@200914021@20.09.14 (040408-300565878):0)
    8.         at bpzl.run(:com.google.android.gms@200914021@20.09.14 (040408-300565878):3)
    9.         at bqam.run(:com.google.android.gms@200914021@20.09.14 (040408-300565878):0)
    10.         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    11.         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    12.         at java.lang.Thread.run(Thread.java:761)
     
  8. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    596
    If that's related to ads it might be unable to fetch any ads to display.

    Are you using the test/developer ad id to test? Sometimes it takes a few days before the real ad id will start to display ads.