Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Rewarded video ad not work on real device (Exception: No such proxy method)

Discussion in 'Unity Ads & User Acquisition' started by ab2700kd, Jan 13, 2022.

Thread Status:
Not open for further replies.
  1. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    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

    image001.png

    Used as tutorials

    Initializing the SDK in Unity
    https://docs.unity.com/ads/Initiali...64.1069724272.1641884113-985477648.1607313241

    Implementing rewarded ads in Unity
    https://docs.unity.com/ads/ImplementingRewardedAdsUnity.htm

    Scripts




    Settings in scripts

    image003.png


    In Unity Dashboard
    Monetization/Settings

    image005.png


    When running Unity Ads in Unity Editor - All is OK

    image007.png

    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)
    image009.png
     
  2. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    Attached Scripts
     

    Attached Files:

  3. Unity_Quinn

    Unity_Quinn

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    102
    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:

    1. 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?
    2. 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.
    3. 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.
    4. Are you currently testing on a physical device or an emulator?
    5. Have you tested with test ads or production ads? Were either of them working?
    I hope this helps! Have a great day!
     
  4. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    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?
     
    Last edited: Jan 14, 2022
  5. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class RewardedAdsButton1 : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
    7. {
    8.        [SerializeField] Button _showAdButton;
    9.        [SerializeField] string _androidAdUnitId = "Rewarded_Android";
    10.        [SerializeField] string _iOSAdUnitId = "Rewarded_iOS";
    11.  
    12.       string _adUnitId = null;
    13.     public string AndroidAdID = "39XXXXX";
    14.     public string iOSAdID = "39XXXXX";
    15.     // Get the Ad Unit ID for the current platform:
    16.     // _adUnitId = null; // This will remain null for unsupported platforms
    17.  
    18.     void Awake()
    19.     {
    20.  
    21. #if UNITY_IOS
    22.         _adUnitId = _iOsAdUnitId;
    23. #endif
    24.  
    25. #if UNITY_ANDROID
    26.          _adUnitId = _androidAdUnitId;
    27. #endif
    28.         //Disable button until ad is ready to show
    29.      //   _showAdButton.interactable = false;
    30.      
    31.     }
    32.  
    33.     // Load content to the Ad Unit:
    34.     public void LoadAd()
    35.     {
    36.         // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
    37.         Debug.Log("Loading Ad: " + _adUnitId);
    38.           Advertisement.Load(_adUnitId, this);
    39.       //  Advertisement.Load(_adUnitId);
    40.     }
    41.  
    42.     // If the ad successfully loads, add a listener to the button and enable it:
    43.     public void OnUnityAdsAdLoaded(string adUnitId)
    44.     {
    45.         Debug.Log("Ad Loaded: " + adUnitId);
    46.  
    47.         if (adUnitId.Equals(_adUnitId))
    48.         {
    49.             // Configure the button to call the ShowAd() method when clicked:
    50.             _showAdButton.onClick.AddListener(ShowAd);
    51.             // Enable the button for users to click:
    52.             _showAdButton.interactable = true;
    53.         }
    54.     }
    55.  
    56.     // Implement a method to execute when the user clicks the button.
    57.     public void ShowAd()
    58.     {
    59.         // Disable the button:
    60.      //   _showAdButton.interactable = false;
    61.         // Then show the ad:
    62.           Advertisement.Show(_adUnitId, this);
    63.        // Advertisement.Show(_adUnitId);
    64.     }
    65.  
    66.     // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    67.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    68.     {
    69.         if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
    70.         {
    71.             Debug.Log("Unity Ads Rewarded Ad Completed");
    72.             // Grant a reward.
    73.  
    74.             // Load another ad:
    75.             Advertisement.Load(_adUnitId, this);
    76.          //   Advertisement.Load(_adUnitId);
    77.         }
    78.     }
    79.  
    80.     // Implement Load and Show Listener error callbacks:
    81.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    82.     {
    83.         Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
    84.         // Use the error details to determine whether to try to load another ad.
    85.     }
    86.  
    87.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    88.     {
    89.         Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
    90.         // Use the error details to determine whether to try to load another ad.
    91.     }
    92.  
    93.     public void OnUnityAdsShowStart(string adUnitId) { }
    94.     public void OnUnityAdsShowClick(string adUnitId) { }
    95.  
    96.     void OnDestroy()
    97.     {
    98.         // Clean up the button listeners:
    99.         _showAdButton.onClick.RemoveAllListeners();
    100.     }
    101. }
    for btnTestAds I maked script

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. using UnityEngine.UI;
    7. using UnityEngine.Advertisements;
    8.  
    9. public class btnTestAdsManager : MonoBehaviour//, IUnityAdsInitializationListener
    10. {
    11.     Button btnTestAds;
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         btnTestAds = GameObject.Find("CanvasMainUI/YYYYYYYY/btnTestAds1").gameObject.GetComponent<Button>();
    16.  
    17.         btnTestAds.onClick.AddListener(() => {
    18.             if ((Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
    19.                || (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork))
    20.             {
    21.                
    22.                 RewardedAdsButton1 ms = new RewardedAdsButton1();              
    23.                 ms.ShowAd();
    24.                 ms.OnUnityAdsShowComplete(ms.AndroidAdID, UnityAdsShowCompletionState.COMPLETED);              
    25.             }
    26.         });
    27.     }
     
  6. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    When I loaded on real device buid from Google Play, in log file is errors about initialization on Unity Ads servers too.

     
  7. Unity_Jae

    Unity_Jae

    Unity Technologies

    Joined:
    Aug 30, 2021
    Posts:
    50
    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. https://docs.unity.com/ads/InitializingTheUnitySDK.htm
    Here is the sample code, which is quite similar to the instruction.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Advertisements;
    6. public class btnTestAdsManager : MonoBehaviour, IUnityAdsInitializationListener
    7. {
    8.     // Please Initialize here. Since this is the manager class.
    9.     [SerializeField] string _androidGameId;
    10.     [SerializeField] string _iOSGameId;
    11.     [SerializeField] bool _testMode = true;
    12.     private string _gameId;
    13.  
    14.     void Awake()
    15.     {
    16.         InitializeAds();
    17.     }
    18.  
    19.     public void InitializeAds()
    20.     {
    21.         _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
    22.             ? _iOSGameId
    23.             : _androidGameId;
    24.         Advertisement.Initialize(_gameId, _testMode);
    25.     }
    26.  
    27.     public void OnInitializationComplete()
    28.     {
    29.         Debug.Log("Unity Ads initialization complete.");
    30.     }
    31.  
    32.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    33.     {
    34.         Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    35.     }
    36.  
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.Advertisements;
    4. public class RewardedAdsButton1 : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
    5. {
    6.     [SerializeField] Button _showAdButton;
    7.     [SerializeField] string _androidAdUnitId = "Rewarded_Android";
    8.     [SerializeField] string _iOSAdUnitId = "Rewarded_iOS";
    9.     string _adUnitId;
    10.  
    11.     void Awake()
    12.     {
    13.         // Get the Ad Unit ID for the current platform:
    14.         _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
    15.         ? _iOsAdUnitId
    16.         : _androidAdUnitId;
    17.  
    18.         //Disable button until ad is ready to show
    19.         _showAdButton.interactable = true;
    20.         // Configure the button to call the ShowAd() method when clicked:
    21.         _showAdButton.onClick.AddListener(ShowAd);
    22.     }
    23.  
    24.     void Start()
    25.     {
    26.         // You can load ads here or you can load ads when you want to load.
    27.         LoadAd();
    28.     }
    29.  
    30.     // Load content to the Ad Unit:
    31.     public void LoadAd()
    32.     {
    33.         // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
    34.         Debug.Log("Loading Ad: " + _adUnitId);
    35.         Advertisement.Load(_adUnitId, this);
    36.     }
    37.  
    38.     // If the ad successfully loads, add a listener to the button and enable it:
    39.     public void OnUnityAdsAdLoaded(string adUnitId)
    40.     {
    41.         Debug.Log("Ad Loaded: " + adUnitId);
    42.     }
    43.     // Implement a method to execute when the user clicks the button.
    44.     public void ShowAd()
    45.     {
    46.         // Disable the button:
    47.         _showAdButton.interactable = false;
    48.         // Then show the ad:
    49.           Advertisement.Show(_adUnitId, this);
    50.     }
    51.     // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    52.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    53.     {
    54.         if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
    55.         {
    56.             Debug.Log("Unity Ads Rewarded Ad Completed");
    57.             // Grant a reward.
    58.             // Load another ad:
    59.             Advertisement.Load(_adUnitId, this);
    60.         }
    61.     }
    62.     // Implement Load and Show Listener error callbacks:
    63.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    64.     {
    65.         Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
    66.         // Use the error details to determine whether to try to load another ad.
    67.     }
    68.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    69.     {
    70.         Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
    71.         // Use the error details to determine whether to try to load another ad.
    72.     }
    73.     public void OnUnityAdsShowStart(string adUnitId) { }
    74.     public void OnUnityAdsShowClick(string adUnitId) { }
    75.     void OnDestroy()
    76.     {
    77.         // Clean up the button listeners:
    78.         _showAdButton.onClick.RemoveAllListeners();
    79.     }
    80. }
    Hope this answer makes sense. If you have any other questions or trouble, please let me know.
     
  8. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
    I wrote earlier that troubles in FIRST INITIALIZING Unity Ads on real devices when App begin connect to Unity Ads servers

    image003Init.png

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Advertisements;
    6.  
    7. public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
    8. {
    9.     [SerializeField] private string _androidGameId = "39XXXXX";
    10.     [SerializeField] private string _iOSGameId = "39XXXXX";
    11.     //  [SerializeField] private bool _testMode;
    12.  
    13.     private string _gameId;
    14.  
    15.     void Awake()
    16.     {
    17.         InitializeAds();
    18.     }
    19.  
    20.     public void InitializeAds()
    21.     {
    22.         _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
    23.             ? _iOSGameId
    24.             : _androidGameId;
    25.  
    26.         //   Advertisement.Initialize(_gameId, _testMode);
    27.         Advertisement.Initialize(_gameId, false);
    28.        
    29.     }
    30.  
    31.     public void OnInitializationComplete()
    32.     {
    33.         Debug.Log("Unity Ads initialization complete.");
    34.     }
    35.  
    36.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    37.     {
    38.         Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    39.     }
    40. }
    41.  
    Log on Start of Initialization of Unity Ads

     
  9. Unity_Quinn

    Unity_Quinn

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    102
    @ab2700kd,

    Thanks for following up on this and providing me with your game ID via PMs. I will follow up with you there.
     
  10. ab2700kd

    ab2700kd

    Joined:
    May 12, 2016
    Posts:
    22
Thread Status:
Not open for further replies.