Search Unity

Ads not working

Discussion in 'Unity Ads' started by RoninGT, Jan 2, 2019.

  1. RoninGT

    RoninGT

    Joined:
    Apr 16, 2018
    Posts:
    10
    So I have a two-part problem. A couple of days ago I was attempting to get my ads working as my game is in early access on the play store however no live ads were firing. I tried everything to get them to work with no luck so I thought maybe I should attempt to update the Unity Ads SDK from the asset store. I noticed that I appeared to have some of the files and others I did not so I choose to add all the missing files. Ever since that I am getting the follow three errors when I attempt to build.

    If I remove the Unity Monitatizon SDK from my project and any mention of it from my scripts the game builds fine. Can anyone help?

    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Java\jdk1.8.0_171\bin\java.exe -classpath "H:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5. Note: there were 22 duplicate class definitions.
    6.       (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
    7.  
    8. FAILURE: Build failed with an exception.
    9.  
    10. * What went wrong:
    11. Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'.
    12. > Job failed, see logs for details
    13.  
    14. * Try:
    15. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    16.  
    17. * Get more help at https://help.gradle.org
    18.  
    19. BUILD FAILED in 58s
    20. ]
    21. stdout[
    22. Starting a Gradle Daemon (subsequent builds will be faster)
    23. :preBuild UP-TO-DATE
    24. :extractProguardFiles
    25. :GooglePlayGamesManifest.plugin:preBuild UP-TO-DATE
    26. :GooglePlayGamesManifest.plugin:preReleaseBuild UP-TO-DATE
    27. :GooglePlayGamesManifest.plugin:checkReleaseManifest
    28. :GooglePlayGamesManifest.plugin:processReleaseManifest
    29. :preReleaseBuild
    30. :GooglePlayGamesManifest.plugin:compileReleaseAidl
    31. :compileReleaseAidl
    32. :GooglePlayGamesManifest.plugin:packageReleaseRenderscript NO-SOURCE
    33. :compileReleaseRenderscript
    34. :checkReleaseManifest
    35. :generateReleaseBuildConfig
    36. :prepareLintJar
    37. :generateReleaseResValues
    38. :generateReleaseResources
    39. :GooglePlayGamesManifest.plugin:compileReleaseRenderscript
    40. :GooglePlayGamesManifest.plugin:generateReleaseResValues
    41. :GooglePlayGamesManifest.plugin:generateReleaseResources
    42. :GooglePlayGamesManifest.plugin:packageReleaseResources
    43. :mergeReleaseResources
    44. :createReleaseCompatibleScreenManifests
    45. :processReleaseManifest
    46. H:\Unity\Repos\Car Jumper\Temp\gradleOut\src\main\AndroidManifest.xml:24:9-31:50 Warning:
    47.     activity#com.google.firebase.auth.internal.FederatedSignInActivity@android:launchMode was tagged at AndroidManifest.xml:24 to replace other declarations but no other declaration present
    48. 'com.google.android.gms.common.api.internal.BasePendingResult$ReleasableResultGuardian'
    49. Note: the configuration refers to the unknown class 'com.google.android.gms.crash.internal.api.CrashApiImpl'
    50. Note: the configuration refers to the unk<message truncated>
    Code (CSharp):
    1. Build completed with a result of 'Failed'
    2. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    3.  
    Code (CSharp):
    1. UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors
    2.   at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0021f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:187
    3.   at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:94
    4. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    5.  
     
  2. RoninGT

    RoninGT

    Joined:
    Apr 16, 2018
    Posts:
    10
    Here is the full first error it was cut off for some reason.

    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Java\jdk1.8.0_171\bin\java.exe -classpath "H:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5. Note: there were 22 duplicate class definitions.
    6.       (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
    7.  
    8. FAILURE: Build failed with an exception.
    9.  
    10. * What went wrong:
    11. Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'.
    12. > Job failed, see logs for details
    13.  
    14. * Try:
    15. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    16.  
    17. * Get more help at https://help.gradle.org
    18.  
    19. BUILD FAILED in 58s
    20. ]
    21. stdout[
    22. Starting a Gradle Daemon (subsequent builds will be faster)
    23. :preBuild UP-TO-DATE
    24. :extractProguardFiles
    25. :GooglePlayGamesManifest.plugin:preBuild UP-TO-DATE
    26. :GooglePlayGamesManifest.plugin:preReleaseBuild UP-TO-DATE
    27. :GooglePlayGamesManifest.plugin:checkReleaseManifest
    28. :GooglePlayGamesManifest.plugin:processReleaseManifest
    29. :preReleaseBuild
    30. :GooglePlayGamesManifest.plugin:compileReleaseAidl
    31. :compileReleaseAidl
    32. :GooglePlayGamesManifest.plugin:packageReleaseRenderscript NO-SOURCE
    33. :compileReleaseRenderscript
    34. :checkReleaseManifest
    35. :generateReleaseBuildConfig
    36. :prepareLintJar
    37. :generateReleaseResValues
    38. :generateReleaseResources
    39. :GooglePlayGamesManifest.plugin:compileReleaseRenderscript
    40. :GooglePlayGamesManifest.plugin:generateReleaseResValues
    41. :GooglePlayGamesManifest.plugin:generateReleaseResources
    42. :GooglePlayGamesManifest.plugin:packageReleaseResources
    43. :mergeReleaseResources
    44. :createReleaseCompatibleScreenManifests
    45. :processReleaseManifest
    46. H:\Unity\Repos\Car Jumper\Temp\gradleOut\src\main\AndroidManifest.xml:24:9-31:50 Warning:
    47.     activity#com.google.firebase.auth.internal.FederatedSignInActivity@android:launchMode was tagged at AndroidManifest.xml:24 to replace other declarations but no other declaration present
    48. 'com.google.android.gms.common.api.internal.BasePendingResult$ReleasableResultGuardian'
    49. Note: the configuration refers to the unknown class 'com.google.android.gms.crash.internal.api.CrashApiImpl'
    50. Note: the configuration refers to the unk<message truncated>
     
  3. RoninGT

    RoninGT

    Joined:
    Apr 16, 2018
    Posts:
    10
    UPDATE: By removing UnityAds.aar I was able to get the game to build without errors. However I am still having issues with getting the ads to display.

    In the editor I get the dummy add that says its working but on device nothing happens.
     
  4. RoninGT

    RoninGT

    Joined:
    Apr 16, 2018
    Posts:
    10
    Here is the code.

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.Monetization;
    7.  
    8. public class UnityAdManager : MonoBehaviour
    9. {
    10.     public static UnityAdManager Instance { get; set; }
    11.  
    12.     public Button coins, rubies, upgrade, powerup;
    13.     public Text coolDown;
    14.  
    15.     private DateTime currentDate, oldDate;
    16.     private TimeSpan timeAway, difference;
    17.     private bool countDown;
    18.  
    19. #if UNITY_IOS
    20.     private string gameId = "iPhone ID";
    21. #elif UNITY_ANDROID
    22.     private string gameId = "Android ID";
    23. #endif
    24.  
    25.     // Use this for initialization
    26.     void Start()
    27.     {
    28.         DontDestroyOnLoad(this);
    29.         Instance = this;
    30.         //Monetization.Initialize(gameId, false);
    31.  
    32.         Debug.Log("DATETIME: " + PlayerPrefs.GetString("videoRewards"));
    33.         CheckTime();
    34.         CheckUnlock();
    35.     }
    36.  
    37.     void Update()
    38.     {
    39.         CheckTime();
    40.  
    41.         if (countDown)
    42.         {
    43.             CountDown();
    44.         }
    45.     }
    46.  
    47.     public void ShowAd(string type)
    48.     {
    49.         StartCoroutine(WaitForAd(type));
    50.     }
    51.  
    52.     IEnumerator WaitForAd(string type)
    53.     {
    54.         while (!Monetization.IsReady(type))
    55.         {
    56.             yield return null;
    57.         }
    58.  
    59.         ShowAdPlacementContent ad = null;
    60.         ad = Monetization.GetPlacementContent(type) as ShowAdPlacementContent;
    61.  
    62.         if (ad != null)
    63.         {
    64.             if (type == "video")
    65.             {
    66.                 ad.Show(AdFinished);
    67.             }
    68.             else if (type == "rewardedVideo")
    69.             {
    70.                 ad.Show(AdFinished);
    71.             }
    72.             else if (type == "unlock1")
    73.             {
    74.                 ad.Show(AdFinished01);
    75.             }
    76.             else if (type == "unlock2")
    77.             {
    78.                 ad.Show(AdFinished02);
    79.             }
    80.             else if (type == "unlock3")
    81.             {
    82.                 ad.Show(AdFinished03);
    83.             }
    84.             else if (type == "unlock4")
    85.             {
    86.                 ad.Show(AdFinished04);
    87.             }
    88.             else
    89.             {
    90.                 ad.Show(AdFinished);
    91.             }
    92.         }
    93.     }
    94.  
    95.     void AdFinished(ShowResult result)
    96.     {
    97.         if (result == ShowResult.Finished)
    98.         {
    99.             // Reward the player
    100.         }
    101.     }
    102.  
    103.     void AdFinished01(ShowResult result)
    104.     {
    105.         if (result == ShowResult.Finished)
    106.         {
    107.             Player.GiveCoins(1000);
    108.             SetDateTime();
    109.             UnlockButton(coins, rubies);
    110.             PlayerPrefs.SetString("CoinButton", "Locked");
    111.         }
    112.     }
    113.  
    114.     void AdFinished02(ShowResult result)
    115.     {
    116.         if (result == ShowResult.Finished)
    117.         {
    118.             Player.GiveRubies(5);
    119.             UnlockButton(rubies, upgrade);
    120.             PlayerPrefs.SetString("RubiesButton", "Locked");
    121.         }
    122.     }
    123.  
    124.     void AdFinished03(ShowResult result)
    125.     {
    126.         if (result == ShowResult.Finished)
    127.         {
    128.             Player.AddHydros(1);
    129.             UnlockButton(upgrade, powerup);
    130.         }
    131.     }
    132.  
    133.     void AdFinished04(ShowResult result)
    134.     {
    135.         if (result == ShowResult.Finished)
    136.         {
    137.             Player.AddNitros(1);
    138.             UnlockButton(powerup, null);
    139.         }
    140.     }
    141.  
    142.     private void CheckTime()
    143.     {
    144.         //Store the current time when it starts
    145.         currentDate = System.DateTime.Now;
    146.  
    147.         //Grab the old time from the player prefs as a long
    148.         long temp = Convert.ToInt64(PlayerPrefs.GetString("videoRewards"));
    149.         oldDate = DateTime.FromBinary(temp);
    150.  
    151.         //Use the Subtract method and store the result as a timespan variable
    152.         difference = currentDate.Subtract(oldDate);
    153.         timeAway = difference;
    154.     }
    155.  
    156.     private void SetDateTime()
    157.     {
    158.         PlayerPrefs.SetString("videoRewards", DateTime.Now.ToBinary().ToString());
    159.     }
    160.  
    161.     private void CheckUnlock()
    162.     {
    163.         if (timeAway >= TimeSpan.FromHours(24))
    164.         {
    165.             countDown = false;
    166.             UnlockButtons();
    167.             coolDown.text = "Your daily rewards are ready to be claimed!";
    168.         }
    169.         else
    170.         {
    171.             countDown = true;
    172.  
    173.             if (PlayerPrefs.GetString("CoinButton") == "Locked")
    174.             {
    175.                 coins.interactable = false;
    176.             }
    177.             else
    178.             {
    179.                 coins.interactable = true;
    180.             }
    181.  
    182.             if (PlayerPrefs.GetString("RubiesButton") == "Locked")
    183.             {
    184.                 rubies.interactable = false;
    185.             }
    186.             else
    187.             {
    188.                 rubies.interactable = true;
    189.             }
    190.  
    191.             if (PlayerPrefs.GetString("UpgradeButton") == "Locked")
    192.             {
    193.                 upgrade.interactable = false;
    194.             }
    195.             else
    196.             {
    197.                 upgrade.interactable = true;
    198.             }
    199.  
    200.             if (PlayerPrefs.GetString("PowerupButton") == "Locked")
    201.             {
    202.                 powerup.interactable = false;
    203.             }
    204.             else
    205.             {
    206.                 powerup.interactable = true;
    207.             }
    208.         }
    209.     }
    210.  
    211.     private void CountDown()
    212.     {
    213.         TimeSpan remaining = TimeSpan.FromHours(24) - timeAway;
    214.         string hours = string.Format("{0}", remaining.Hours);
    215.         string mins = string.Format("{0}", remaining.Minutes);
    216.         string secs = string.Format("{0}", remaining.Seconds);
    217.  
    218.         if (remaining.Hours > 0)
    219.         {
    220.             if (coolDown != null)
    221.                 coolDown.text = "Daily Rewards Unlock in " + hours + " hours, " + mins + " minutes, and " + secs + " seconds!";
    222.         }
    223.         else if (remaining.Minutes > 0)
    224.         {
    225.             if (coolDown != null)
    226.                 coolDown.text = "Daily Rewards Unlock in " + mins + " minutes, and " + secs + " seconds!";
    227.         }
    228.         else
    229.         {
    230.             if (coolDown != null)
    231.                 coolDown.text = "Daily Rewards Unlock in " + secs + " seconds!";
    232.         }
    233.     }
    234.  
    235.     private void UnlockButtons()
    236.     {
    237.         coins.interactable = true;
    238.         rubies.interactable = false;
    239.         upgrade.interactable = false;
    240.         powerup.interactable = false;
    241.  
    242.         PlayerPrefs.SetString("CoinButton", "Unlocked");
    243.         PlayerPrefs.SetString("RubiesButton", "Unlocked");
    244.         PlayerPrefs.SetString("UpgradeButton", "Unlocked");
    245.         PlayerPrefs.SetString("PowerupButton", "Unlocked");
    246.     }
    247.  
    248.     public void UnlockButton(Button cbtn, Button nbtn)
    249.     {
    250.         Debug.Log("UnlockButton Called");
    251.         Debug.Log(cbtn);
    252.         Debug.Log(nbtn);
    253.  
    254.         if (cbtn != null)
    255.             cbtn.interactable = false;
    256.      
    257.         if (nbtn != null)
    258.             nbtn.interactable = true;
    259.     }
    260. }
     
    Last edited: Jan 2, 2019
  5. ivieslinda

    ivieslinda

    Joined:
    Apr 18, 2013
    Posts:
    1
    I would like to bump this because I am having the same issue on 2018.3. On Android I am having an issue with Monetization.Initialize() it seems. Using Unity Monetization 3.0. The game will load, but as soon as the script runs, the game will crash while Monetizatin.Initialize() is running, generally after a second of the script being invoked.

    Editor works just fine and displays the proper test ad.
     
    NikitaVahrameev21 likes this.
  6. NikitaVahrameev21

    NikitaVahrameev21

    Joined:
    Mar 25, 2017
    Posts:
    4
    I have exactly the same problem on unity2018.3.0! When building a project on an android, during the initialization the game stops responding. Commenting on the line with initialization solves the problem.
     
    Last edited: Jan 14, 2019
  7. NikitaVahrameev21

    NikitaVahrameev21

    Joined:
    Mar 25, 2017
    Posts:
    4
    I was able to solve the problem: I was helped by turning off Unity Ads in the services window and turning on Unity Analytics:) And check in manifest that unity ads are completely removed from your project. You should have only Unity Monetization package in the project
     
  8. doomtoo

    doomtoo

    Joined:
    Feb 16, 2015
    Posts:
    39
    Thanks! That worked for me too!

    Summary:

    Don't follow Unity's instructions, which are completely wrong.
    Disable Ads Under services (but leave Analytics)
    Remove Advertisement from Windows->Package Manager
    Install 'Unity Monetization 3.0' from the asset store (5th one when searching 'Monetization', non existent when searching 'ads')