The ad shows without any issues in the editor however when I build and run through play store internal testing, the ads will not show. There is an error in my logcat however I can not decipher the error after researching.
Can anyone explain or help?
In reward show method
d__5:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
AdRewardsController:ShowRewarded()
UnityEngine.Events.UnityAction:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.EventSystems.EventFunction1:Invoke(T1, BaseEventData) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()
AndroidJavaException: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.h.d, parameter userId
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.h.d, parameter userId
at com.unity3d.mediation.RewardedAdShowOptions$S2SRedeemData.(Unknown Source:2)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:214)
at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AndroidJNISafe.NewObject (System.IntPtr clazz, System.IntPtr methodID, UnityEngine.jvalue[ ] args) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AndroidJavaObject._Android
Rewarded failed to show: Failed to show - java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.h.d, parameter userId
d__5:MoveNext()
System.Threading.ContextCallback:Invoke(Object)
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
System.Action:Invoke()
System.Threading.ContextCallback:Invoke(Object)
System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
System.Threading.Tasks.Task:FinishContinuations()
System.Threading.Tasks.Task:Finish(Boolean)
System.Threading.Tasks.Task1:TrySetException(Object) System.Threading.Tasks.TaskCompletionSource1:TrySetException(Exception)
Unity.Services.Mediation.RewardedAd:OnShowFailed(Object, ShowErrorEventArgs)
System.EventHandler`1:Invoke(Object, TEventArgs)
System.Threading.SendOrPostCallback:Invoke(Object)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext
AdUnit with adUnitId: Rewarded_Android has already loaded.
Hi @nobluff67 !
This would mean you are passing S2SData, without a userId (passing null). This is not allowed, and S2SData if used has to contain a userId.
The S2S data is used to validate legitimate rewards, to avoid players cheating. Generally the userId is a game specific value used to identify the player getting rewarded. If you do not have a S2S system set up, we recommend you do not pass any values into the Show call (showOptions is an optional parameter for Show).
Thanks for providing this extra insight. So far I haven’t been able to reproduce this issue. In Player Settings > Publishing Settings, do you have Custom Main Gradle Template selected or not?
Thanks for sharing a solution that worked for you. Nonetheless, the original code snippet should be able to work, if you reply to my question above, we can continue researching the issue.
No I don’t, just progaurd-user.txt. I believe I have added to this file since the issue, so I am not sure if this would have solved my specific issue. The additions to the progaurd file did resolve some other google related issues, so maybe they overlap. I will create a new build later on tonight, with the original code - await ad.ShowAsync(showOptions); to see if the issue persists on my side.
@DeclanMcPartlin i just tested and the problem still persists, in other words my previous changes to the progaurd file did not make a difference to this specific issue. In the mean time I have removed the showOptions portion of the await ad.ShowAsync(showOptions); As mentioned before, it works when I remove the showOptions, so at least its not halting my production work.
I’ve just checked with the team and this issue will be handled in the next patch release, thanks again for reaching out and sharing this. For the time being, I’d recommend using Autoreload by providing filler values for S2S like so:
This works, however I would like to make sure we are not getting our wires crossed. I am using
ShowRewarded() and not ShowRewardedWithOptions(). The ShowRewarded() method was the one that was giving me issues, and the one I changed with your suggested code.
public async void ShowRewarded()
{
Debug.Log("In reward show method");
Debug.Log("showad " + m_RewardedAd.AdState);
completeAdWatched = false;
if (m_RewardedAd?.AdState == AdState.Loaded)
{
try
{
//RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
//showOptions.AutoReload = true;
//await m_RewardedAd.ShowAsync();
//Debug.Log("Rewarded Shown!");
RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
S2SRedeemData s2SData;
s2SData.UserId = "placeholder";
s2SData.CustomData = "placeholder";
showOptions.S2SData = s2SData;
showOptions.AutoReload = true;
await m_RewardedAd.ShowAsync(showOptions);
}
catch (ShowFailedException e)
{
Debug.LogWarning($"Rewarded failed to show: {e.Message}");
}
}
}
public async void ShowRewardedWithOptions()
{
if (m_RewardedAd?.AdState == AdState.Loaded)
{
try
{
//Here we provide a user id and custom data for server to server validation.
RewardedAdShowOptions showOptions = new RewardedAdShowOptions();
showOptions.AutoReload = true;
S2SRedeemData s2SData;
s2SData.UserId = "my cool user id";
s2SData.CustomData = "{\"reward\":\"Gems\",\"amount\":20}";
showOptions.S2SData = s2SData;
await m_RewardedAd.ShowAsync(showOptions);
Debug.Log("Rewarded Shown!");
}
catch (ShowFailedException e)
{
Debug.LogWarning($"Rewarded failed to show: {e.Message}");
}
}
}