Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Admob shows in Editor, but not on a real Android device.

Discussion in 'General Discussion' started by vvladimirgaming, May 1, 2021.

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

    vvladimirgaming

    Joined:
    May 29, 2020
    Posts:
    3
    So, I implemented admob into my project, the problem is that in Editor it is showing perfectly, both test ad and real one. But after build on Android neither one works.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5. using GoogleMobileAds;
    6.  
    7.  
    8. public class onClick : MonoBehaviour
    9. {
    10.     private RewardedAd rewardedAd;
    11.     void Start() {
    12.        
    13.     }
    14.     private void OnMouseDown()
    15.     {
    16.         this.rewardedAd = new RewardedAd("ca-app-pub-5346701446101044/4602400235");
    17.         AdRequest request = new AdRequest.Builder().Build();
    18.         this.rewardedAd.LoadAd(request);
    19.         Debug.Log("Work");
    20.     }
    21. }
    22.  
     
  2. vvladimirgaming

    vvladimirgaming

    Joined:
    May 29, 2020
    Posts:
    3
    Sorry, guys, thats not the right code, sorry once again
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5. using GoogleMobileAds;
    6. using GoogleMobileAds.Common;
    7. using System;
    8.  
    9. public class ButtonClick : MonoBehaviour
    10. {
    11.     public RewardedAd rewardedAd;
    12.     public GameObject obj;
    13.     // Start is called before the first frame update
    14.     public void Start()
    15.     {
    16.         MobileAds.Initialize(initStatus => { });
    17.         this.rewardedAd = new RewardedAd("ca-app-pub-3940256099942544/5224354917");
    18.         AdRequest request = new AdRequest.Builder().Build();
    19.         this.rewardedAd.LoadAd(request);
    20.         this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
    21.         this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
    22.         this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
    23.     }
    24.     public void ShowRewardVideo() {
    25.         if (rewardedAd.IsLoaded())
    26.         {
    27.             rewardedAd.Show();
    28.         }
    29.     }
    30.     public void HandleUserEarnedReward(object sender, Reward args)
    31.     {
    32.         int coins = PlayerPrefs.GetInt("kermamoneta");
    33.         int adRew = coins + 15;
    34.         PlayerPrefs.SetInt("kermamoneta", adRew);
    35.     }
    36.     public void HandleRewardedAdClosed(object sender, EventArgs args)
    37.     {
    38.         Destroy(obj);
    39.     }
    40.     public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
    41.     {
    42.         Destroy(obj);
    43.     }
    44. }
    45.  
     
  3. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    628
    AdMob rewarded ads will show a test ad in editor but will not work in apk unless released through app store.

    It does not need to be 'published', but it must be downloaded from apple/google.

    For google play, use internal testing
    For apple use test flight
     
    Lorrak likes this.
  4. vvladimirgaming

    vvladimirgaming

    Joined:
    May 29, 2020
    Posts:
    3
    Big thanks, i hope it works!
     
  5. HulSoft

    HulSoft

    Joined:
    Oct 11, 2022
    Posts:
    1
    Does this also work same for (banner , interstitial ads)??
     
  6. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    628
    yes
     
  7. imrankarimi009

    imrankarimi009

    Joined:
    Dec 10, 2020
    Posts:
    3
    rewarded and banner ads are not showing while interstitial ad is working perfectly (on mobile device)
     
Thread Status:
Not open for further replies.