Rewarded video Ad work on Unity Editor, but not work on real device
Unity: 2021.2.5f1
Unity Ads (Advertisement): 3.7.5 (August 02, 2021)
Project Settings
Services/Ads
Used as tutorials
Initializing the SDK in Unity
https://docs.unity.com/ads/InitializingTheUnitySDK.htm?_ga=2.237553664.1069724272.1641884113-985477648.1607313241
Implementing rewarded ads in Unity
https://docs.unity.com/ads/ImplementingRewardedAdsUnity.htm
Scripts
Settings in scripts
In Unity Dashboard
Monetization/Settings
When running Unity Ads in Unity Editor - All is OK
When I launch the game on the real device (Android device) and press the ad button, I get the log
Exception: No such proxy method: UnityEngine.Advertisements.AndroidShowListener.onUnityAdsShowFailure(UnityEngine.AndroidJavaObject,UnityEngine.AndroidJavaObject,System.String)
Hi @ab2700kd ,
Thanks for reaching out! I’m sorry to hear about this.
I took a quick look through your code and didn’t spot any obvious issues. Although, I have a few questions/observations for you:
- When are you making your load calls? I noticed that you have one load call in the OnUnityAdsShowComplete callback, but where are you making your first load call?
- I noticed in the screenshots you’ve included above that the game ID in the service window isn’t matching the other game IDs you’ve included. It’s worth making another passthrough to double-check that you are using the correct set of game IDs everywhere.
- It is possible that there is an issue with your project settings. Can you please look through your project settings for anything that looks like it could cause an error? If you don’t spot anything, please provide me with your game ID in a private message and I will take a look.
- Are you currently testing on a physical device or an emulator?
- Have you tested with test ads or production ads? Were either of them working?
I hope this helps! Have a great day!
I tested with production ads. Test Ads on real Android device not worked too.
On physical devices: smarthone Sony XZ3 and tablet Samsung T-835
I think that it is not initialized on the Unity Ads servers?
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class RewardedAdsButton1 : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] Button _showAdButton;
[SerializeField] string _androidAdUnitId = "Rewarded_Android";
[SerializeField] string _iOSAdUnitId = "Rewarded_iOS";
string _adUnitId = null;
public string AndroidAdID = "39XXXXX";
public string iOSAdID = "39XXXXX";
// Get the Ad Unit ID for the current platform:
// _adUnitId = null; // This will remain null for unsupported platforms
void Awake()
{
#if UNITY_IOS
_adUnitId = _iOsAdUnitId;
#endif
#if UNITY_ANDROID
_adUnitId = _androidAdUnitId;
#endif
//Disable button until ad is ready to show
// _showAdButton.interactable = false;
}
// 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);
// Advertisement.Load(_adUnitId);
}
// If the ad successfully loads, add a listener to the button and enable it:
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log("Ad Loaded: " + adUnitId);
if (adUnitId.Equals(_adUnitId))
{
// Configure the button to call the ShowAd() method when clicked:
_showAdButton.onClick.AddListener(ShowAd);
// Enable the button for users to click:
_showAdButton.interactable = true;
}
}
// Implement a method to execute when the user clicks the button.
public void ShowAd()
{
// Disable the button:
// _showAdButton.interactable = false;
// Then show the ad:
Advertisement.Show(_adUnitId, this);
// Advertisement.Show(_adUnitId);
}
// Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
// Load another ad:
Advertisement.Load(_adUnitId, this);
// Advertisement.Load(_adUnitId);
}
}
// 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.
}
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.
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
void OnDestroy()
{
// Clean up the button listeners:
_showAdButton.onClick.RemoveAllListeners();
}
}
for btnTestAds I maked script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class btnTestAdsManager : MonoBehaviour//, IUnityAdsInitializationListener
{
Button btnTestAds;
// Start is called before the first frame update
void Start()
{
btnTestAds = GameObject.Find("CanvasMainUI/YYYYYYYY/btnTestAds1").gameObject.GetComponent<Button>();
btnTestAds.onClick.AddListener(() => {
if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
|| (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
{
RewardedAdsButton1 ms = new RewardedAdsButton1();
ms.ShowAd();
ms.OnUnityAdsShowComplete(ms.AndroidAdID, UnityAdsShowCompletionState.COMPLETED);
}
});
}
When I loaded on real device buid from Google Play, in log file is errors about initialization on Unity Ads servers too.
Hello ab2700kd,
Thank you for providing your code.
Seems like you are instantiating a class that inherits Monobehaviour class. But please attach the script to one of your game objects in the scene and use it. If not, you probably see the warning message in the console. Also, you are manually calling OnUnityAdsShowComplete
but this method will be automatically called when Unity Ads has been shown, so you don’t need to call this method. And please do not call it manually.
Hence, I would recommend you to follow the instruction without instancing the Monobehaviour class or calling OnUnityAdsShowComplete method. Initializing the SDK in Unity
Here is the sample code, which is quite similar to the instruction.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class btnTestAdsManager : MonoBehaviour, IUnityAdsInitializationListener
{
// Please Initialize here. Since this is the manager class.
[SerializeField] string _androidGameId;
[SerializeField] string _iOSGameId;
[SerializeField] bool _testMode = true;
private string _gameId;
void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOSGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class RewardedAdsButton1 : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] Button _showAdButton;
[SerializeField] string _androidAdUnitId = "Rewarded_Android";
[SerializeField] string _iOSAdUnitId = "Rewarded_iOS";
string _adUnitId;
void Awake()
{
// Get the Ad Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
//Disable button until ad is ready to show
_showAdButton.interactable = true;
// Configure the button to call the ShowAd() method when clicked:
_showAdButton.onClick.AddListener(ShowAd);
}
void Start()
{
// You can load ads here or you can load ads when you want to load.
LoadAd();
}
// 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);
}
// If the ad successfully loads, add a listener to the button and enable it:
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log("Ad Loaded: " + adUnitId);
}
// Implement a method to execute when the user clicks the button.
public void ShowAd()
{
// Disable the button:
_showAdButton.interactable = false;
// Then show the ad:
Advertisement.Show(_adUnitId, this);
}
// Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
// 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.
}
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.
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
void OnDestroy()
{
// Clean up the button listeners:
_showAdButton.onClick.RemoveAllListeners();
}
}
Hope this answer makes sense. If you have any other questions or trouble, please let me know.
I wrote earlier that troubles in FIRST INITIALIZING Unity Ads on real devices when App begin connect to Unity Ads servers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
[SerializeField] private string _androidGameId = "39XXXXX";
[SerializeField] private string _iOSGameId = "39XXXXX";
// [SerializeField] private bool _testMode;
private string _gameId;
void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOSGameId
: _androidGameId;
// Advertisement.Initialize(_gameId, _testMode);
Advertisement.Initialize(_gameId, false);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
}
Log on Start of Initialization of Unity Ads
@ab2700kd ,
Thanks for following up on this and providing me with your game ID via PMs. I will follow up with you there.