How to test a Unity app with Google AdMob on a test device?
I have AdMob displaying the demo images for banner ads within the Unity Game Engine Editor fine, but when I side load the app onto my phone nothing is being displayed... How do I test ads on my test device? I have set up the device as a test device in AdMob's UI, and I've tried using both my real ad unit id's and the test ones with no success. My account has been verified and I've waited up to a couple of days to see if it just needs to time as I've read that was the issue for some other people. I've seen some people say that I need to set up a payment method, but that's greyed out for me saying that I don't need to set one up until my "earnings threshold has been reached." I will have code and log files below for additional assistance with troubleshooting. Thanks! (NOTE: I have removed my actual adUnitId's for the sake of privacy)
Code for Banner Ad's Below: C# in Unity
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api;
public class Ads : MonoBehaviour
{ private BannerView bannerView;
// Start is called before the first frame update
void Start()
{
// Initializes the GoogleMobileAds (GoogleAdMob) SDK
MobileAds.Initialize(initStatus => { });
this.RequestBanner();
}
private void RequestBanner()
{
// Clean up banner ad before creating a new one.
if (this.bannerView != null)
{
this.bannerView.Destroy();
}
// !! below ad unit IDs are TEST ids -> will need to change to active ID's
#if UNITY_ANDROID
string adUnitId = "adUnitId";
#elif UNITY_IPHONE
string adUnitId = "adUnitId";
#else
string adUnitId = "unexpected_platform";
#endif
// creating custom sized banner using adaptive banner method -> works the best so far
AdSize adaptiveSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
this.bannerView = new BannerView(adUnitId, adaptiveSize, AdPosition.Bottom);
// Create a 320x50 banner at the bottom of the screen.
// this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
// Loading the ad to the screen
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Register ad events
this.bannerView.OnAdLoaded += this.HandleAdLoaded;
this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
this.bannerView.OnAdOpening += this.HandleAdOpened;
this.bannerView.OnAdClosed += this.HandleAdClosed;
this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;
// Load the banner with the request.
this.bannerView.LoadAd(request);
}
// region Banner callback handlers
public void HandleAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
MonoBehaviour.print(String.Format("Ad Height: {0}, width: {1}",
this.bannerView.GetHeightInPixels(),
this.bannerView.GetWidthInPixels()));
}
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
MonoBehaviour.print("HandleFailedToReceiveAd event received with message: " + args.Message);
}
public void HandleAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdClosed event received");
}
public void HandleAdLeftApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeftApplication event received");
}
}
Log from running app on phone:
02-08 08:37:05.021 25320 25343 E Unity : AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener 02-08 08:37:05.021 25320 25343 E Unity : java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener 02-08 08:37:05.021 25320 25343 E Unity : at java.lang.Class.classForName(Native Method) 02-08 08:37:05.021 25320 25343 E Unity : at java.lang.Class.forName(Class.java:454) 02-08 08:37:05.021 25320 25343 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 02-08 08:37:05.021 25320 25343 E Unity : at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 02-08 08:37:05.021 25320 25343 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 02-08 08:37:05.021 25320 25343 E Unity : at android.os.Handler.dispatchMessage(Handler.java:102) 02-08 08:37:05.021 25320 25343 E Unity : at android.os.Looper.loop(Looper.java:223) 02-08 08:37:05.021 25320 25343 E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 02-08 08:37:05.021 25320 25343 E Unity : Caused by: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener 02-08 08:37:05.021 25320 25343 E Unity : ... 8 more 02-08 08:37:05.021 25320 25343 E Unity : at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in :0 02-08 08:37:05.021 25320 25343 E Unity : at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <000000000000000000000 02-08 08:37:51.566 25320 25343 E Unity : NullReferenceException: Object reference not set to an instance of an object. 02-08 08:37:51.566 25320 25343 E Unity : at GoogleMobileAds.Api.MobileAds.Initialize (System.Action`1[T] initCompleteAction) [0x00000] in :0 02-08 08:37:51.566 25320 25343 E Unity : at Ads.Start () [0x00000] in :0 02-08 08:37:51.566 25320 25343 E Unity : 02-08 08:37:51.566 25320 25343 E Unity : (Filename: currently not available on il2cpp Line: -1) 02-08 08:37:51.566 25320 25343 E Unity : 02-08 08:38:17.531 25320 25343 E Unity : NullReferenceException: Object reference not set to an instance of an object. 02-08 08:38:17.531 25320 25343 E Unity : at GoogleMobileAds.Api.MobileAds.Initialize (System.Action`1[T] initCompleteAction) [0x00000] in :0 02-08 08:38:17.531 25320 25343 E Unity : at Ads.Start () [0x00000] in :0 02-08 08:38:17.531 25320 25343 E Unity : 02-08 08:38:17.531 25320 25343 E Unity : (Filename: currently not available on il2cpp Line: -1) 02-08 08:38:17.531 25320 25343 E Unity :