Unity ads work on editor but not on build

In the editor my ad manager works totally fine, but when it’s built and launched from mobile device it doesn’t.

My ad manager’s code:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

public class GameOverAdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{

    public string gameID = "";
    public string rewardedID = "";
    public Button buttonReward;

    [SerializeField] bool testMode = true;

    public AudioSource audioKasing;
    public Text melonbillsCount;
    private GameObject logic;



    // Start is called before the first frame update
    void Start()
    {
        buttonReward.interactable = false;

        InitializeAds();
        //LoadRewardedAd();

        logic = GameObject.Find("Logic Manager");
    }

    public void InitializeAds()
    {

        if (!Advertisement.isInitialized && Advertisement.isSupported)
        {
            Advertisement.Initialize(gameID, testMode, this);
        }

    }

    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
        buttonReward.interactable = true;
    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }

    public void LoadRewardedAd()
    {
        // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
        Advertisement.Load(rewardedID, this);
    }

    public void OnUnityAdsAdLoaded(string adUnitId)
    {
        // Optionally execute code if the Ad Unit successfully loads content.
    }

    public void ShowRewardedAd()
    {
        // Then show the ad:
        Advertisement.Show(rewardedID, this);
    }

    public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    {
        if (adUnitId.Equals(rewardedID) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
        {
            Debug.Log("Unity Ads Rewarded Ad Completed");
            // Grant a reward.

            PlayerPrefs.SetInt("MelonBills", PlayerPrefs.GetInt("MelonBills", 0) + logic.GetComponent<LogicManager>().playerEarnedMoney);
            audioKasing.volume = PlayerPrefs.GetFloat("FxVolume");
            audioKasing.Play();

            melonbillsCount.color = Color.yellow;
            melonbillsCount.text = (logic.GetComponent<LogicManager>().playerEarnedMoney * 2).ToString();
        }
    }

    // Implement Load and Show Listener error callbacks:
    public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
        LoadRewardedAd();
    }

    public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
        LoadRewardedAd();
    }

    public void OnUnityAdsShowStart(string adUnitId) { }
    public void OnUnityAdsShowClick(string adUnitId) { }

}

In the logs of the android app I get this when I launch the scene:

Initializing Unity Ads
ClassNotFoundException: com.unity3d.services.banners.IUnityBannerListerner

But as you can see I have no banner in my script and nowhere in my project, so I find that very weird and annoying. If someone has the same problem and found the solution…

1 Like

Hello,
What Unity version do you use?

1 Like