Search Unity

UnityAds not working on Android physical device

Discussion in 'Unity Ads' started by faithstudio2016, Sep 21, 2017.

  1. faithstudio2016

    faithstudio2016

    Joined:
    Apr 20, 2017
    Posts:
    4
    I am using the following code for my game. It used to work for iOS. but now i am having issue on running on my Android Device (It worked before I added the "package_name" on "store_id" under the "Organization" -> "Game" -> "Google Play").

    Looking forward to hear some solution.
    @unity-nikkolai

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.Advertisements;
    7.  
    8. public class AdsReward : MonoBehaviour {
    9.  
    10.     public static AdsReward instance;
    11.  
    12.     [Header("Ads Settings")]
    13.     public bool activateTestingGUI;
    14.     public bool enableTestMode;
    15.  
    16.     #if UNITY_ANDROID
    17.  
    18.     private string gameID = "XXXXXXX";
    19.  
    20.     #elif UNITY_IOS
    21.  
    22.     private string gameID = "XXXXXXX";
    23.  
    24.     #endif
    25.  
    26.     void Awake(){
    27.  
    28.         if (instance == null) {
    29.  
    30.             Debug.Log ("Created Instance");
    31.  
    32.             instance = this;
    33.             DontDestroyOnLoad (instance.gameObject);
    34.         } else if(instance != this){
    35.  
    36.             Debug.Log ("Destroying Duplicated Instance");
    37.  
    38.             Destroy (this.gameObject);
    39.         }
    40.     }
    41.  
    42.     void Start(){
    43.  
    44.         StartCoroutine (InitializedAds ());
    45.     }
    46.  
    47.     void OnGUI(){
    48.  
    49.         if (activateTestingGUI) {
    50.  
    51.             float width = 0;
    52.             float height = 0;
    53.  
    54.             if (Screen.width > Screen.height) {
    55.                 //Landscape
    56.                 width = Screen.width/3;
    57.                 height = Screen.height / 16;
    58.  
    59.             } else {
    60.                 //Portrait
    61.                 width = Screen.width / 3;
    62.                 height = Screen.height / 16;
    63.             }
    64.  
    65.             if (Advertisement.isSupported) {
    66.            
    67.                 GUI.TextField (new Rect ((Screen.width / 2) - (width/2), 0, width, height),
    68.                     "Unity Ads Supported");
    69.             }
    70.  
    71.             if (Advertisement.IsReady ("rewardedVideo")) {
    72.            
    73.                 GUI.TextField (new Rect ((Screen.width / 2) - (width/2), height , width, height),
    74.                     "rewardedVideo (Ready)");
    75.             } else {
    76.  
    77.                 GUI.TextField (new Rect ((Screen.width / 2) - (width/2), height , width, height),
    78.                     "rewardedVideo (NOT! Ready)");
    79.             }
    80.  
    81.             if (Advertisement.IsReady ("video")) {
    82.  
    83.                 GUI.TextField (new Rect ((Screen.width / 2) - (width/2), height*2, width, height),
    84.                     "video (Ready)");
    85.             } else {
    86.  
    87.                 GUI.TextField (new Rect ((Screen.width / 2) - (width/2), height*2, width, height),
    88.                     "video (NOT! Ready)");
    89.             }
    90.  
    91.             if (GUI.Button      (new Rect ((Screen.width / 2) - (width/2),height*3, width, height),
    92.                 "Show Ads")) {
    93.  
    94.                 ShowAds ();
    95.             }
    96.         }  
    97.     }
    98.  
    99.     private IEnumerator InitializedAds(){
    100.  
    101.         if (Advertisement.isSupported) {
    102.            
    103.             Advertisement.Initialize (gameID, enableTestMode);
    104.         }
    105.  
    106.  
    107.         while (!Advertisement.isInitialized || !Advertisement.IsReady ()) {
    108.  
    109.             yield return new WaitForSeconds (0.5f);
    110.         }
    111.     }
    112.  
    113.  
    114.     public void ShowAds(){
    115.  
    116.         if (Advertisement.IsReady ("rewardedVideo")) {
    117.  
    118.             Advertisement.Show ("rewardedVideo", new ShowOptions () {
    119.  
    120.                 resultCallback = HandleRewardAdResult
    121.             });
    122.         } else if (Advertisement.IsReady ("video")) {
    123.            
    124.             Advertisement.Show ("video", new ShowOptions () {
    125.  
    126.                 resultCallback = HandleVideoAdResult
    127.             });
    128.         }
    129.     }
    130.  
    131.     //-----------------------------------------------------------------------------
    132.  
    133.     public void ShowRewardVideoAds(){
    134.  
    135.         if (Advertisement.IsReady ("rewardedVideo")) {
    136.  
    137.             Advertisement.Show ("rewardedVideo", new ShowOptions () {
    138.  
    139.                 resultCallback = HandleRewardAdResult
    140.             });
    141.         }
    142.     }
    143.  
    144.     private void HandleRewardAdResult(ShowResult result){
    145.  
    146.         switch (result) {
    147.  
    148.         case ShowResult.Failed:
    149.             //Debug.Log ("Failed To Load The RewardAds");
    150.             break;
    151.         case ShowResult.Skipped:
    152.             //Debug.Log ("Skip RewardAds");
    153.             break;
    154.         case ShowResult.Finished:
    155.             //Debug.Log ("Finished RewardAds");
    156.             //GAGameAnalyist.ourGAGameAnalysit.TrackRewardedAds ();
    157.             break;
    158.         }
    159.     }
    160.  
    161.     //-----------------------------------------------------------------------------
    162.  
    163.     public void ShowVideoAds(){
    164.  
    165.         if(Advertisement.IsReady("video")){
    166.  
    167.             Advertisement.Show ("video", new ShowOptions () {
    168.  
    169.                 resultCallback = HandleVideoAdResult
    170.             });
    171.         }
    172.     }
    173.  
    174.     private void HandleVideoAdResult(ShowResult result){
    175.  
    176.         switch (result) {
    177.  
    178.         case ShowResult.Failed:
    179.             //Debug.Log ("Failed To Load The VideoAds");
    180.             break;
    181.         case ShowResult.Skipped:
    182.             //Debug.Log ("Skip VideoAds");
    183.             break;
    184.         case ShowResult.Finished:
    185.             //Debug.Log ("Finished VideoAds");
    186.             //GAGameAnalyist.ourGAGameAnalysit.TrackVideoAds ();
    187.  
    188.             break;
    189.         }
    190.     }
    191. }
    192.  
     
  2. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,168
    No need to ping people directly, we will pick up new posts :)

    In any case, please check device logs using "adb logcat -v time UnityAds:V *:S" from command line, and see if you get any errors.

    /Rasmus
     
  3. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Hi,

    Thanks for bringing this up!

    Have you integrated Ads to your project from the Services window? - I recommend checking if your issues is the same as here: https://forum.unity.com/threads/state-and-the-future-of-the-unity-ads-services-integration.494936/

    If this doesn't resolve your issue - please send an e-mail to unityads-support@unity3d.com and provide the following details:
    - Your Ads SDK version and integration path
    - Game IDs
    - The content of your UnityConnectSettings.asset file (check the forum link above)
    - Logs with Unity Ads in debug mode
     
  4. faithstudio2016

    faithstudio2016

    Joined:
    Apr 20, 2017
    Posts:
    4
    Thank you #rasmus for the fast response. My sincere apology for tagging specifically to someone cause I saw him many times answering about the unity ads on other thread.
    I will try to take your valuable advice.

    How can I execute the following "adb logcat -v time UnityAds:V *:S" from commandline. Anyway to learn?

    Thanks in advance.
     
  5. faithstudio2016

    faithstudio2016

    Joined:
    Apr 20, 2017
    Posts:
    4
    Yes, I was working with the assetstore version, but when the ads got broken after I made the change on the google play store, I though switching to ads services from the editor might solve the problem. Looks to me, I need to change back to asset store version and see how it goes.

    I have also checked the "ProjectSettings/UnityConnectSettings.asset", it seems fine as you mentioned on the following thread.

    Looking forward to find the solution with the issue.
     
  6. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    You can find adb under your Android SDK / platform-tools / adb

    https://developer.android.com/studio/command-line/logcat.html

    Did switching to the Asset Store version of the SDK resolve the issue?
     
  7. IlliaHalfvild

    IlliaHalfvild

    Joined:
    Mar 11, 2017
    Posts:
    1
    Try disabling only 'built-in Ads extension' but not the Ads service itself. It was my problem