- Home /
Test Ads Not Showing on Android Device
Hi, so I made a Unity Android game and am trying to put test ads on it. I have a very simple AdMob script, when run in the Editor I get notified that the ad is loaded however when testing the apk on my phone, nothing happens. How can I fix this?
I have an created an Admob app and put in the app ID in the Editor as well.
Thank you
The Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class Admob : MonoBehaviour
{
//external references
private BannerView bannerView;
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/6300978111"; //test
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
// Start is called before the first frame update
void Start()
{
#if UNITY_ANDROID
string appId = "ca-app-pub-2432741135954738~7585816177"; //your admob app id
#elif UNITY_IPHONE
string appId = "ca-app-pub-3940256099942544~1458002511";
#else
string appId = "unexpected_platform";
#endif
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(appId);
RequestBanner();
ShowBanner();
}
//show banner
public void ShowBanner()
{
bannerView.Show();
}
}
Answer by H_Ishfaq · Mar 08, 2021 at 02:31 PM
hi . have you found any solution. im having same problem . . :(
Answer by arndnwlv · Nov 29, 2021 at 03:16 PM
I struggled a lot with that topic in the past days so I post my possible fixes for this.
Dont use a test id for the App id itself. Use always you own app id that you got from Admob. Only for the Ad(banners, natives...) itself you should use test ids.
use try-catch blocks around your ad creation and catch the error if it appears. With that i found out that i got a type initializier exception, Which practically meant that the admob package didnt build in the app. that probably indicated that gradle didnt build the app correctly. But Using other gradle installation than the recommendes caused more problems so i tried a lot of unity versions.
so my solutions was the following steps:
unity version: 2020.3.23f1
import Admob plugin version 6.1.2: UNCHECK external dependency manager in the import settings.
Import External Dependency Manager for Unity 1.2.167
external dependency manager-> Android Resolver-> resolve.if you get an error: go to preferences->uncheck recommended JDK-> press browse->check recommended jdk(this seems to update the jdk access). after an error you should use android resolver-> force resolve.
Put your app id under assets-> google mobile ads-> settings an initialize your app with:
MobileAds.Initialize(initStatus => { });
If these things don't work, you probably have to test a lot configurations with different version of admob,unity and maybe gradle. Good luck!