Unity admob 广告无法在 android 上运行

Unity admob ads not working on android

我刚刚发布了名为 Dodge:android 和 iOS 的游戏,当时测试广告在 iOS 上有效。在两个平台上启动游戏时,android 上没有广告,Admob 控制面板中也没有请求。当有iOS的时候。

这是我用来调用广告的代码:

using UnityEngine;
using UnityEngine.SceneManagement;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class Menu : MonoBehaviour {

private BannerView bannerView;

private void Awake()
{
    SetupAds();
}

void SetupAds()
{
    if (PlayerPrefs.HasKey("AdFree"))
        return;

    #if UNITY_IPHONE
        string appId = "ca-app-pub-9468963556585973~6866139959";
    #elif UNITY_ANDROID
        string appId = "ca-app-pub-9468963556585973~5324184926";
    #else 
        sting appId = "unexpected_platform";
    #endif

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

    this.RequestBanner();

}

private void RequestBanner()
{
    #if UNITY_IPHONE
        string adUnitId = "ca-app-pub-9468963556585973/6704565848";
    #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-9468963556585973/7268247018";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();

    // Load the banner with the request.
    bannerView.LoadAd(request);
}

public void StartGame ()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}

public void DisableAds()
{
    Debug.Log("Ads disabled");
    if (PlayerPrefs.HasKey("AdFree"))
        print("Ads already removed");
    else{
        PlayerPrefs.SetInt("AdFree", 1);
        PlayerPrefs.Save();

        bannerView.Destroy();
    }
}
}

只需重新导入 Google AdMob SDK。就这些了。