AppLovin / AppLovin-MAX-Unity-Plugin

130 stars 35 forks source link

java.lang.IllegalArgumentException: Empty ad unit ID specified #278

Closed rbyjoswald closed 1 year ago

rbyjoswald commented 1 year ago

MAX Plugin Version

5.6.4

Unity Version

2021.3.19f1

Device/Platform Info

Android 8.1, 10, 11, 12, 13

Current Behavior

java.lang.IllegalArgumentException: Empty ad unit ID specified com.applovin.mediation.ads.MaxInterstitialAd.(SourceFile:57) com.applovin.mediation.unity.MaxUnityAdManager.retrieveInterstitial(MaxUnityAdManager.java:1710) com.applovin.mediation.unity.MaxUnityAdManager.isInterstitialReady(MaxUnityAdManager.java:476) com.applovin.mediation.unity.MaxUnityPlugin.isInterstitialReady(MaxUnityPlugin.java:894) com.unity3d.player.UnityPlayer.nativeRender(Native Method) com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) android.os.Handler.dispatchMessage(Handler.java:102) android.os.Looper.loopOnce(Looper.java:226) android.os.Looper.loop(Looper.java:313) com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) UnityEngine.AndroidJNISafe.CheckException () (at <00000000000000000000000000000000>:0) UnityEngine.AndroidJNISafe.CallStaticBooleanMethod (System.IntPtr clazz, System.IntPtr methodID, UnityEngine.jvalue[] args) (at <00000000000000000000000000000000>:0) UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)

Expected Behavior

IllegalArgumentException should not be thrown when the a non null and non empty and non whitespace adUnitId is given to the Max SDK.

How to Reproduce

First I check if adUnitId IsNullOrWhiteSpace. Then I check MaxSdk.IsInterstitialReady(adUnitId). Then I call MaxSdk.ShowInterstitial(adUnitId). For some users the above exception is thrown on Android. An identical client on iOS does not throw this exception.

Additional Info

No response

thomasmso commented 1 year ago

@rbyjoswald - This is likely a user error, we'd only through that exception if you've managed to pass in an empty Ad Unit ID. Please double-check your integration code. For your reference, here's a snippet of the MaxInterstitialAd code that is throwing:

image
rbyjoswald commented 1 year ago

I agree that a user error is the most likely cause. That said, I went over the code plenty of times. Also the same app only throws these error on Android, not iOS despite using exactly the same codebase. Let me paste how I invoke it:

if (string.IsNullOrEmpty(adUnitId) == false /*actually redundant, see next*/ && string.IsNullOrWhiteSpace(adUnitId) == false && HasPreloadedInterstitialAd && MaxSdk.IsInterstitialReady(adUnitId)) {
  Log("ShowInterstitialAd() - interstitial.IsLoaded()");
  MaxSdk.ShowInterstitial(adUnitId);
} else {
  LogWarning($"Failed to show interstitial. HasPreloadedInterstitialAd: {HasPreloadedInterstitialAd}, IsInterstitialReady: {MaxSdk.IsInterstitialReady(adUnitId)}, adUnitId: {adUnitId}");
}

One additional question. Is MaxSdk.IsInterstitialReady safe to invoke with a null or empty adUnitId? I debug log the result of MaxSdk.IsInterstitialReady in the branch where I know that one of the above conditions fails. Could that call also throw the exception?

JonathanLiuApp commented 1 year ago

@rbyjoswald You want to ensure that MaxSdk.IsInterstitialReady isn't called with a null or empty adUnitId, as that will cause the error you are seeing.

rbyjoswald commented 1 year ago

Thanks for the info. It would actually be great to have that as part of the documentation. I mean which method can throw what exception. I don't really see a reference manual online for the SDK, but even without that, it could be documented in the c# side of the SDK.

santoshbagadi commented 1 year ago

We'll look into including more info in our API docs in an upcoming release

santoshbagadi commented 9 months ago

We've added non-null requirements to our SDK API docs in C# in plugin version 6.2.0.