Search Unity

Unity Ads not showing on Android device

Discussion in 'Unity Ads' started by onemoreuser091, Nov 15, 2014.

  1. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    I have a Script with this line:
    Code (CSharp):
    1. Advertisement.Initialize("MyGameCode",true);
    Also I created a button with this script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4. public class AdTest : MonoBehaviour {
    5.  
    6.     public dfButton AdShow;
    7.     public string zone;
    8.     public bool isReady;
    9.  
    10.     void Update(){
    11.         isReady = Advertisement.isReady(zone);
    12.         AdShow.Text = isReady ? "Show Ad" : "Waiting...";
    13.         AdShow.IsInteractive = isReady;
    14.     }
    15. public void ClickShowAd(){
    16.         if (isReady){
    17.             Advertisement.Show(zone);
    18.     }
    19.     }
    20.     }
    Test Ads appear on Editor:



    When I click the button...It works.


    But on device it's not loading.
    Only waiting...


    I'm also using this asset so I don't know if it's related to it or...
    https://www.assetstore.unity3d.com/en/#!/content/10825
    And here is my manifest:
    http://pastebin.com/3kXnKSW1
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    236
    onemoreuser091 hello,

    Could you pls try using Advertisement.isReady(zone); out of update() function.

    thank you,
     
  3. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    Well...my first try was with this one:
    https://gist.github.com/wcoastsands/3d003528a76f94fa2ede
    Which I found in this thread:
    http://forum.unity3d.com/threads/ads-dont-display-on-android.270920/
    But I don't have a gameobject called UnityAds.
    I tried on an empty project in it seems to work so I don't know what wrong.Maybe it's because of android native plugin. I thought my manifest was correct.
    I also saw that unity ads comes with a "device.jar" file and the other plugin has the "android native.jar" one.
     
  4. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    In your AdTest script, how are you setting the value for isReady? Like Salazar suggested, you should be using Advertisement.isReady(zone), which you could use with isReady as a property, like so:
    Code (CSharp):
    1. public bool isReady { get { return Advertisement.isReady(zone); }}
    Also, if you can post a link to the logcat output, it should provide clues to what's happening.
     
  5. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    It's not a problem of the code because it works on editor and in the device too when I build it from other empty project.
    I saw some AndroidJava exception with class AndroidNativeBridge so I think it's related to the android native plugin but I don't know how to fix this.Anyway I'm not sure if this the problem...
     

    Attached Files:

    Last edited: Nov 16, 2014
  6. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    So I changed the manifest from this:
    Code (CSharp):
    1. <activity android:name="com.androidnative.AndroidNativeBridge" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:launchMode="singleTask">
    2.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    3.       <intent-filter>
    4.         <action android:name="android.intent.action.MAIN" />
    5.         <category android:name="android.intent.category.LAUNCHER" />
    6.       </intent-filter>
    7.     </activity>
    8.  
    9.         <activity
    10.               android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
    11.               android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    12.               android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    13.               android:hardwareAccelerated="true" />
    14.     </application>
    To this one:
    Code (CSharp):
    1.  
    2.     <activity
    3. android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:launchMode="singleTask">
    4.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    5.       <intent-filter>
    6.         <action android:name="android.intent.action.MAIN" />
    7.         <category android:name="android.intent.category.LAUNCHER" />
    8.       </intent-filter>
    9.     </activity>
    10.  
    11.  
    12.         <activity
    13.               android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
    14.               android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    15.               android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    16.               android:hardwareAccelerated="true" />
    17.     </application>
    Unity Ads needs unity 3d activity to be the main? Now Test ads appear but I can't close them so I'm a bit closer...anyway I still don't know what the correct way to have them both working.

    Edit: I don't know if I implemented correctly or not but at least video ad seems to work now. I still can't close the picture ad.
     
    Last edited: Nov 18, 2014
  7. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Did you only change the name parameter of the activity tag?

    Not seeing anything obvious from the logcat you posted. Would you mind exporting your project as an asset package and sending me a link to it in a private conversation?

    Thanks
     
  8. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Also, not clear on where the manifest you're using came from, or if it's valid.

    Unity Ads 1.0.4 (SDK 1.3.9) has it's manifest stored under Plugins/Android/unityads.

    The contents of which are as follows:
    Code (XML):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.     package="com.unity3d.ads.android"
    4.     android:versionCode="1"
    5.     android:versionName="1.0" >
    6.  
    7.     <application>
    8.         <activity
    9.               android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
    10.               android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    11.               android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    12.               android:hardwareAccelerated="true" />
    13.     </application>
    14.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    15.     <uses-permission android:name="android.permission.INTERNET" />
    16.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    17. </manifest>
     
  9. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    The manifest I have is a merged version of Android Native plugin and Unity Ads.
    And yes, if I tag the NativeBridge and filter as main and launcher then unity ads won't work.
    Also setting unityplayer as main still has some bugs like blackscreen with pictureads.
    But I need this plugin to be main activity or the other features(billing,social,etc...) won't work.

    My current project is too big in size and is too messy so I will send a package reproducing the problem I have, with only Unity ads and this plugin.
     
  10. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    I thought to remove the other plugin at the moment because I'm not using any important feature. But now even empty project with only unity ads imported,has stopped working.
    When I touch the show ad button to show a test picture ad, screen just goes grey like it tries to launch but never launches...
    I tried to download the unity ads package again but same problem.
    So now:
    -Unity ads+Native plugin: Unity ads never Initialize.
    -Unity ads only: Unity ads Initialize,find ads but picture ads never launch and only stay at the grey screen
     
    Last edited: Nov 20, 2014
  11. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    I sent a link to the package a while ago... It's not working? You didn't had time to test?
    How can I fix this?What I'm doing wrong? Or at least how to get picture ads working.Please help.
     
  12. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    I got the package, thank you. Just haven't had the chance to test yet. Will get a chance to do so today.

    Keep in mind picture ads are still in beta. There may not be any campaigns running for your region. Be sure to initialize Unity Ads with testMode enabled to make sure you can at least see test ads.

    I'll follow up with you again here soon after I've had a chance to test the package. Thanks for pinging me on this.
     
  13. mwolff282

    mwolff282

    Joined:
    Jan 13, 2013
    Posts:
    2
    I am having a very similar problem to the one originally posted here. I can run my ad script in the editor and it will tell me that everything is working ok but when I build the game it will endlessly tell me that it is "Waiting...". I have also tried using an example project and building that to my tablet and that also does the exact same thing.
     
  14. onemoreuser091

    onemoreuser091

    Joined:
    Nov 15, 2014
    Posts:
    14
    All I could do for now is to disable picture ads when no more videos are available in the Unity Ads placement settings. Although this is not a solution. I understand that this picture ads still in beta so no picture ads are available to show. But the problem is when I use this script button (Waiting ...) If the button works, and appears (SHOW AD). Then what happens is that the screen turns grey, like when an app is started. But, no ad was shown and I can not return to the game.
     
  15. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Make sure that if the zone value is empty, that it gets set to null before being passed. When a null value is set, Unity Ads uses the default ad placement zone. The same is not true when an empty string is set.

    Code (CSharp):
    1. if (string.IsNullOrEmpty(zone)) zone = null;
    I've recently updated the demo project. Might be worth looking through the revised helper and example scripts. See the commit logs for change notes. Let me know if you have any questions.
     
  16. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    262
    I am having the same problem. UnityAds and Everyplay does not work if I change the main activity on AndroidManifest. I am using AndroidNative plugin which overrides the main activity, please let me know how did you solve this?
     
  17. HappySaila

    HappySaila

    Joined:
    Dec 15, 2015
    Posts:
    2
    FIXED!

    After fiddling around a lot I found the solution.

    In Unity Ads > click on your game > Click on your game store listing (eg the tab that has your game ID in >
    Click on settings next to ad filtering > And turn "Override client test mode OFF!
     
  18. orrinjones

    orrinjones

    Joined:
    Jan 14, 2017
    Posts:
    5
    I am having the same problem. The test ads show in the editor but not in the game build. turning "Override client test mode - OFF" doesn't fix the problem either.
     
  19. 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.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Advertisements;
    6.  
    7. public class AdsReward : MonoBehaviour {
    8.  
    9.     public static AdsReward instance;
    10.  
    11.     [Header("Ads Settings")]
    12.     public bool enableTestMode;
    13.  
    14.     #if UNITY_ANDROID
    15.  
    16.     private string gameID = "XXXXXXX";
    17.  
    18.     #elif UNITY_IOS
    19.  
    20.     private string gameID = "XXXXXXX";
    21.  
    22.     #endif
    23.  
    24.     void Awake(){
    25.  
    26.  
    27.         if (instance == null) {
    28.  
    29.             instance = this;
    30.             StartCoroutine (InitializedAds ());
    31.         } else if (instance != this)
    32.             Destroy (gameObject);
    33.  
    34.         DontDestroyOnLoad (gameObject);
    35.  
    36.  
    37.     }
    38.  
    39.     void Start(){
    40.  
    41.         //instance = this;
    42.  
    43.         //StartCoroutine (InitializedAds ());
    44.     }
    45.  
    46.     private IEnumerator InitializedAds(){
    47.  
    48.         if (Advertisement.isSupported) {
    49.  
    50.             Advertisement.Initialize (gameID, enableTestMode);
    51.         }
    52.  
    53.  
    54.         while (!Advertisement.isInitialized || !Advertisement.IsReady ()) {
    55.  
    56.             yield return new WaitForSeconds (0.5f);
    57.         }
    58.     }
    59.  
    60.  
    61.     public void ShowAds(){
    62.  
    63.         if (Advertisement.IsReady ("rewardedVideo")) {
    64.  
    65.             Advertisement.Show ("rewardedVideo", new ShowOptions () {
    66.  
    67.                 resultCallback = HandleRewardAdResult
    68.             });
    69.         }else if(Advertisement.IsReady("video")){
    70.  
    71.             Advertisement.Show ("video", new ShowOptions () {
    72.  
    73.                 resultCallback = HandleVideoAdResult
    74.             });
    75.         }
    76.     }
    77.  
    78.     //-----------------------------------------------------------------------------
    79.  
    80.     public void ShowRewardVideoAds(){
    81.  
    82.         if (Advertisement.IsReady ("rewardedVideo")) {
    83.  
    84.             Advertisement.Show ("rewardedVideo", new ShowOptions () {
    85.  
    86.                 resultCallback = HandleRewardAdResult
    87.             });
    88.         }
    89.     }
    90.  
    91.     private void HandleRewardAdResult(ShowResult result){
    92.  
    93.         switch (result) {
    94.  
    95.         case ShowResult.Failed:
    96.             //Debug.Log ("Failed To Load The RewardAds");
    97.             break;
    98.         case ShowResult.Skipped:
    99.             //Debug.Log ("Skip RewardAds");
    100.             break;
    101.         case ShowResult.Finished:
    102.             //Debug.Log ("Finished RewardAds");
    103.             //GAGameAnalyist.ourGAGameAnalysit.TrackRewardedAds ();
    104.             break;
    105.         }
    106.     }
    107.  
    108.     //-----------------------------------------------------------------------------
    109.  
    110.     public void ShowVideoAds(){
    111.  
    112.         if(Advertisement.IsReady("video")){
    113.  
    114.             Advertisement.Show ("video", new ShowOptions () {
    115.  
    116.                 resultCallback = HandleVideoAdResult
    117.             });
    118.         }
    119.     }
    120.  
    121.     private void HandleVideoAdResult(ShowResult result){
    122.  
    123.         switch (result) {
    124.  
    125.         case ShowResult.Failed:
    126.             //Debug.Log ("Failed To Load The VideoAds");
    127.             break;
    128.         case ShowResult.Skipped:
    129.             //Debug.Log ("Skip VideoAds");
    130.             break;
    131.         case ShowResult.Finished:
    132.             //Debug.Log ("Finished VideoAds");
    133.             //GAGameAnalyist.ourGAGameAnalysit.TrackVideoAds ();
    134.  
    135.             break;
    136.         }
    137.     }
    138. }
    139.  
     
  20. zedsmith52

    zedsmith52

    Joined:
    May 10, 2017
    Posts:
    9
    Same problem here. Works in Unity editor, but the version that's in the android play store doesn't show the advert.
    I'm a bit of a newby, but I can't see why it should work in testing, then not on the target device.


    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;
    using UnityEngine.Advertisements;
    public class Advertising : MonoBehaviour {
    //---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
    #if UNITY_IOS
    private string gameId = "2680606";
    #elif UNITY_ANDROID
    private string gameId = "2680604";
    #else
    private string gameId = "";
    #endif
    //-------------------------------------------------------------------//
    private string placementID;
    private ShowOptions options;
    private bool showOn = true;
    void Start ()
    {
    Advertisement.Initialize(gameId);
    ShowVideo("rewardedVideo");
    }
    void Update () {
    // Debug.Log ("Advertisement Is Ready " + Advertisement.IsReady (placementID));
    if (Advertisement.IsReady (placementID) && showOn) {
    Advertisement.Show (placementID, options);
    showOn = false;
    }
    }
    void ShowVideo (string pID)
    {
    placementID = pID;
    // Debug.Log("Unity Ads initialized: " + Advertisement.isInitialized);
    // Debug.Log("Unity Ads is supported: " + Advertisement.isSupported);
    // Debug.Log("Unity Ads test mode enabled: " + Advertisement.testMode);
    //StartCoroutine();
    options = new ShowOptions();
    options.resultCallback = HandleShowResult;
    }
    void HandleShowResult (ShowResult result)
    {
    if(result == ShowResult.Finished) {
    //Debug.Log("Video completed - Offer a reward to the player");
    // Reward your player here.
    PlayerStatic.gold = PlayerStatic.gold + 50* PlayerStatic.level;
    //Debug.Log ("Player got: " + 50 * PlayerStatic.level);
    //Debug.Log (PlayerStatic.gold);
    PlayerStatic.Save ();
    }else if(result == ShowResult.Skipped) {
    //Debug.LogWarning("Video was skipped - Do NOT reward the player");
    }else if(result == ShowResult.Failed) {
    //Debug.LogError("Video failed to show");
    }
    if (result == ShowResult.Finished || result == ShowResult.Skipped || result == ShowResult.Failed) {
    SceneManager.LoadScene("GameShop");
    }
    }
    }

     
  21. Deleted User

    Deleted User

    Guest

    me too i'm facing same problem , it'll be a disaster to upload my game to android store , and Ads won't work . waw that will be amazing ...
    though i'm wondering why is it a bit complicated to implement unity Ads ,
     
    kodlan likes this.
  22. jaspercayne

    jaspercayne

    Joined:
    Nov 29, 2014
    Posts:
    4
    Still having this issue on the 2019 branches too. Everything works correctly in the editor, my gameID is set properly, test mode override makes no difference.

    Anyone figure out a working solution to this yet?
     
    kodlan and Amex4152 like this.
  23. NARKWOOD

    NARKWOOD

    Joined:
    Apr 1, 2019
    Posts:
    2
    Same problem HERE !!!!
    I'm desperate
     
  24. jaspercayne

    jaspercayne

    Joined:
    Nov 29, 2014
    Posts:
    4
    I've got it! I unchecked the built in ad plugin from the services window, reimported the monetization plugins from the asset store, and tried again and ads are being served now.

    Your mileage may vary, but this worked for me.
     
    kodlan likes this.
  25. kodlan

    kodlan

    Joined:
    Nov 13, 2013
    Posts:
    1
    Hi,
    I'm also having the same problem - test ads are shown in the editor but not on actual device.
    Tried unchecking build in ad plugin from serivices menu, reimported from asset store.
    And nothing helps...
    Any suggestions what else to try would be really appreciated!

    I've spent sooo much time on this, and it still doesn't work. Please help!
     
  26. riyadhuae

    riyadhuae

    Joined:
    Feb 8, 2019
    Posts:
    4
    Hi,

    Can you help me creating apk that shows REAL ads without monetisation and non on playstore. Just a test show ads apk.

    Thanks
     
  27. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,613
    Please stop asking this same question on multiple threads.