0

I got this error message when I run the game on my real Android device but works fine on my Unity Editor. I saw some similar posts on how to fix and I followed but seems the issue still happens.

I followed the Unity doc for setting up the Ads, the code below is from the Unity website.

    showListener is null, you will not receive any callbacks
    AndroidJavaException: java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
    java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
Caused by: java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener

My code:

using UnityEngine;
using UnityEngine.Advertisements;
 
public class InterstitialAd : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
    private string _androidAdUnitId = "Interstitial_Android";
    private string _iOsAdUnitId = "Interstitial_iOS";
    private string _adUnitId;
 
    void Awake()
    {
        // Get the Ad Unit ID for the current platform:
        _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? _iOsAdUnitId
            : _androidAdUnitId;
    }
 
    // Load content to the Ad Unit:
    public void LoadAd()
    {
        // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
        Debug.Log("Loading Ad: " + _adUnitId);
        Advertisement.Load(_adUnitId, this);
    }
 
    // Show the loaded content in the Ad Unit:
    public void ShowAd()
    {
        // Note that if the ad content wasn't previously loaded, this method will fail
        Debug.Log("Showing Ad: " + _adUnitId);
        Advertisement.Show(_adUnitId, this);
    }
 
    // Implement Load Listener and Show Listener interface methods: 
    public void OnUnityAdsAdLoaded(string adUnitId)
    {
        // Optionally execute code if the Ad Unit successfully loads content.
    }
 
    public void OnUnityAdsFailedToLoad(string _adUnitId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit: {_adUnitId} - {error.ToString()} - {message}");
        // Optionally execute code if the Ad Unit fails to load, such as attempting to try again.
    }
 
    public void OnUnityAdsShowFailure(string _adUnitId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {_adUnitId}: {error.ToString()} - {message}");
        // Optionally execute code if the Ad Unit fails to show, such as loading another ad.
    }
 
    public void OnUnityAdsShowStart(string _adUnitId) { }
    public void OnUnityAdsShowClick(string _adUnitId) { }
    public void OnUnityAdsShowComplete(string _adUnitId, UnityAdsShowCompletionState showCompletionState) { }
}
Si Dang
  • 25
  • 1
  • 6
  • You may have made method names but you dont seem to be using them and im not sure a second parameter of "this" in fact im almost surprised it compiled as that second parameter is supposed to be for showoptions – BugFinder Jun 14 '23 at 07:36
  • @BugFinder the ShowAd method is attached to a button, the LoadAd method is called in the other script where I initialized the Unity ads. The "this" refers to IUnityAdsInitializationListener – Si Dang Jun 14 '23 at 07:40
  • Not according to their documentation :P https://docs.unity3d.com/2017.1/Documentation/ScriptReference/Advertisements.Advertisement.html disagrees – BugFinder Jun 14 '23 at 07:54
  • @BugFinder this doc: https://docs.unity.com/ads/en/manual/ImplementingBasicAdsUnity – Si Dang Jun 14 '23 at 08:12
  • btw big banner on that page, its not being updated and has moved to a new better one.. – BugFinder Jun 14 '23 at 09:00

1 Answers1

0

I go to Assests -> Reimport All. It works now!

Si Dang
  • 25
  • 1
  • 6