Search Unity

[SOLVED] Latest Monetization SDK causing Gradle Build Error...

Discussion in 'Unity Ads & User Acquisition' started by NoctisShadowzel, Jun 3, 2019.

  1. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    To test my work-in-progress game (on Android), I wanted to make a test today. I tried 5 times, all failed. While trying to build I disabled Antivirus && Firewall (because I changed my Antivirus recently) but didn't worked.
    After that I read Error Logs and there was some parts that mentioned Unity Ads; here is the full log:

    After that I Google'd for a while, because while downloading Latest Monetization SDK I noticed that there are people who had problems; after that,
    I erased Unity Ads Package from Package Manager -- didn't solve problem.
    I disabled Ad Service from Services Tab -- didn't solve problem.
    Also, if I didn't miss anything, none of this changes changed the Error Log.

    Can someone help me to solve this problem??

    PS.
    After downloading the Monetization SDK I moved its folder from Assets folder to another folder inside Assets folder. (I wanted my files to be organized...) Will this cause this problem?

    PSS.
    I downloaded latest Monetization SDK, because without it,
    IUnityAdsListener
    Interface didn't worked correctly. I didn't see any error to inform me about un-implemented methods, but ads wasn't working (I used
    RewardedAdsButton.cs
    from the Integration Guide) when I downloaded SDK interface started working correctly.
     
    Last edited: Jun 4, 2019
  2. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    EDIT: To check if there is a problem with any of my Ads related scripts, I am going to share them too. I'm sorry if post is a little long. Maybe Unity can take a look at this problem.

    > RewardedAdsManager.cs
    Code (CSharp):
    1. using System.Collections;[/B]
    2. [B]using UnityEngine;
    3. using UnityEngine.Advertisements;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.UI;
    6.  
    7. public class RewardedAdsManager : MonoBehaviour, IUnityAdsListener
    8. {
    9. #if UNITY_IOS
    10.     private string gameId = "#######";
    11. #elif UNITY_ANDROID
    12.     private string gameId = "#######";
    13. #endif
    14.  
    15.     [SerializeField] Button watchAdButton = null, leaveButton = null;
    16.     [SerializeField] Sprite noAds = null, watchAds = null;
    17.  
    18.     public string myPlacementId = "rewardedVideo";
    19.  
    20.     bool alreadyWatchedAnAd = false;    float adCooldown = 10f;
    21.  
    22.     ScoreManager scoreManager = null;
    23.     Player playerScript = null;
    24.  
    25.     void Start()
    26.     {
    27.         leaveButton.onClick.AddListener(delegate { Leave(); });
    28.  
    29.         // Set interactivity to be dependent on the Placement’s status:
    30.         watchAdButton.interactable = Advertisement.IsReady(myPlacementId);
    31.  
    32.         // Map the ShowRewardedVideo function to the button’s click listener:
    33.         if (watchAdButton) watchAdButton.onClick.AddListener(ShowRewardedVideo);
    34.  
    35.         // Initialize the Ads listener and service:
    36.         Advertisement.AddListener(this);
    37.  
    38.         if (Advertisement.isInitialized == false)
    39.             Advertisement.Initialize(gameId, true);
    40.        
    41.         scoreManager = ScoreManager.instance;
    42.     }
    43.  
    44.     void Update()
    45.     {
    46.         if (!watchAdButton.interactable)
    47.             watchAdButton.image.sprite = noAds;
    48.         else
    49.             watchAdButton.image.sprite = watchAds;
    50.     }
    51.  
    52.     // Implement a function for showing a rewarded video ad:
    53.     void ShowRewardedVideo()
    54.     {
    55.         Advertisement.Show(myPlacementId);
    56.     }
    57.  
    58.     // Implement IUnityAdsListener interface methods:
    59.     public void OnUnityAdsReady(string placementId)
    60.     {
    61.         // If the ready Placement is rewarded, activate the button:
    62.         if (placementId == myPlacementId && !alreadyWatchedAnAd)
    63.             watchAdButton.interactable = true;
    64.         else
    65.             watchAdButton.interactable = false;
    66.     }
    67.  
    68.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    69.     {
    70.         // Define conditional logic for each ad completion status:
    71.         if (showResult == ShowResult.Finished) //GIVE REWARD TO PLAYER...
    72.         {
    73.             if(SceneManager.GetActiveScene().buildIndex == 0)
    74.             {   //If user is in "Main Menu", :: give user "2xScoreBooster" for 2 games ::
    75.                 scoreManager.EnableDoubleScore();
    76.                 StartCoroutine(StartCooldown());
    77.             }
    78.             else if(SceneManager.GetActiveScene().buildIndex == 1)
    79.             {   //If user is in "Game", :: Revive Player ::
    80.                 playerScript = GameObject.FindWithTag("Player").GetComponent<Player>();
    81.  
    82.                 if (playerScript.DeathLimit > 0)
    83.                     playerScript.Revive();
    84.             }
    85.         }
    86.         else if (showResult == ShowResult.Skipped)
    87.         {
    88.             // Do not reward the user for skipping the ad.
    89.         }
    90.         else if (showResult == ShowResult.Failed)
    91.         {
    92.             Debug.LogWarning("The ad did not finish due to an error.");
    93.         }
    94.     }
    95.  
    96.     public void OnUnityAdsDidError(string message)
    97.     {
    98.         // Log the error.
    99.     }
    100.  
    101.     public void OnUnityAdsDidStart(string placementId)
    102.     {
    103.         // Optional actions to take when the end-users triggers an ad.
    104.     }
    105.  
    106.     IEnumerator StartCooldown()
    107.     {
    108.         alreadyWatchedAnAd = true;
    109.  
    110.         while(adCooldown > 0)
    111.         {
    112.             yield return null;
    113.             adCooldown -= Time.deltaTime;
    114.         }
    115.         alreadyWatchedAnAd = false;
    116.     }
    117.  
    118. #region NON-ADS-RELATED METHODS
    119.     void Leave()
    120.     {
    121.         if (SceneManager.GetActiveScene().buildIndex == 0)
    122.             MenuManager.instance.StartGame();
    123.         else if (SceneManager.GetActiveScene().buildIndex == 1)
    124.             MenuManager.instance.ChangeScene("Ending Menu");
    125.     }
    126. #endregion
    127. }



    >InitializeAds.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class InitializeAds : MonoBehaviour
    5. {
    6. #if UNITY_IOS
    7.     private string gameId = "#######";
    8. #elif UNITY_ANDROID
    9.     private string gameId = "#######";
    10. #endif
    11.  
    12.     bool testMode = true;
    13.  
    14.     void Start()
    15.     {
    16.         if (!Advertisement.isInitialized)
    17.             Advertisement.Initialize(gameId, testMode);
    18.     }
    19. }

    TY for taking time^^
     
  3. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    EDIT2: I checked a few forums to see what people did to solve similiar (not same) problems, again. I,
    Disabled Crash Reporting Setting from
    , no luck.
     
    Last edited: Jun 7, 2019
  4. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    EDIT3: After all tries I made to solve the problem (as I mentioned in my posts), I solved the problem by deleting Plugins folder (Assets/Plugins). I think that is a critical step that you need to do while deleting the "Unity Ads" from Package Manager.
    Whatever, if you have a problem, you can watch the steps I watched. (Oh also, I am using Unity 2018.3.8f1 Personal, with latest versions of Java, JDK etc. I didn't wanted to update and be late to finishing my game while learning new things that come with 2019.* version.)

    I hope you will have a good day. Also, dear Unity team; Please tell your users side-effects of your decisions. If we need to use "Monetization SDK" instead of "Unity Ads Package" (that comes with project) tell us how to do this *correctly*.