Search Unity

Type or Namespace 'GoogleMobileAds' could not be found.

Discussion in 'Editor & General Support' started by ksoiza5, Mar 13, 2016.

  1. ksoiza5

    ksoiza5

    Joined:
    Feb 17, 2016
    Posts:
    9
    Hi.. So I'm pretty much ready to release a 2D project I've worked on and after importing the latest admob release file, changing the manifest, copying my google-play-services_lib file onto the corresponding folder when everything seems to be ready to go, I get this error saying the GoogleMobileAds type or namespace cannot be found.

    I've copied the script below in case I'm just being a nutter and missing something obvious. The whole error says the following: (3,7):error CS0246: The type or namespace name 'GoogleMobileAds' could not be found. Are you missing a using directive or an assembly reference?

    using UnityEngine;
    using System.Collections;
    using GoogleMobileAds.Api;

    public class UnhappyAds : MonoBehaviour
    {

    // Use this for initialization
    void Start()
    {
    RequestBanner();
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void RequestBanner()
    {
    #if UNITY_ANDROID
    string adUnitId = "The App ID";
    #elif UNITY_IPHONE
    string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the banner with the request.
    bannerView.LoadAd(request);
    }
    }
     
  2. ksoiza5

    ksoiza5

    Joined:
    Feb 17, 2016
    Posts:
    9
    Nobody? Really?
     
  3. MoMughal

    MoMughal

    Joined:
    Mar 2, 2017
    Posts:
    3
    I'm getting the same issue. Do let me know how you resolved it :)
     
  4. DoomerDGR8

    DoomerDGR8

    Joined:
    May 15, 2015
    Posts:
    12
    KHADmama and sivabalan12 like this.
  5. Herbie72

    Herbie72

    Joined:
    Oct 21, 2017
    Posts:
    4
    I'm also getting the same issue. Also the latest release did not resolve it.
    GoogleMobileAds could still not be found.
    Does anybody has a solution for this?
     
  6. MR-01

    MR-01

    Joined:
    Jun 27, 2016
    Posts:
    2
    I have the same issue, even when I use the latest version of the Unity Admob Plugin!
    can anyone help, please?
     
  7. KAwshik_Khan

    KAwshik_Khan

    Joined:
    Jul 31, 2018
    Posts:
    1
    i have the same issue ..plz help me
     
  8. charlyXue

    charlyXue

    Joined:
    Jul 10, 2018
    Posts:
    1
    I have the same issue. too
     
  9. daud5221

    daud5221

    Joined:
    Sep 4, 2018
    Posts:
    1
    I found the solution. In the Monodevelope, at the search text box, type "GoogleMobileAds.Api" then select it. And try again with using GoogleMobileAds.Api.
     

    Attached Files:

    deltagaming323 likes this.
  10. unknownsk

    unknownsk

    Joined:
    Jan 16, 2020
    Posts:
    36
    Did anyone fixed that? I have same problem :(
     
  11. unknownsk

    unknownsk

    Joined:
    Jan 16, 2020
    Posts:
    36
    It doeanot works :(
     
  12. unknownsk

    unknownsk

    Joined:
    Jan 16, 2020
    Posts:
    36
    Same did you fixed that?
     
  13. sivabalan12

    sivabalan12

    Joined:
    Jul 5, 2019
    Posts:
    11
  14. adeight

    adeight

    Joined:
    Jan 10, 2020
    Posts:
    8
    You need to import a package to the unity project:
    1- click this link and click DOWNLOAD THE PLUGIN: https://developers.google.com/admob/unity/start
    2- DOWNLOAD the about 400 kb file with .unitypackage extension
    3- go to unity : Assets => import package and select the file you downloaded in step 2. check all boxes and import
     
    RedZack likes this.
  15. Olives

    Olives

    Joined:
    Mar 27, 2013
    Posts:
    1
    Ok through much trial and error I think I got it. After importing the latest package, Go to directory Assets/GoogleMobileAds/Editor and select GoogleMobileAds.Editor. In the inspector check "Use GUIDs" and platforms below that. After that just click the Apply button. I also force resolved packages and restarted the editor after applying these settings for the error message to go away.

    upload_2020-9-6_10-58-26.png
     
  16. ajeets1978

    ajeets1978

    Joined:
    Mar 10, 2019
    Posts:
    25
    this doesn't work, I am having the same issues after updating all the plugins and adding google play billing.
     
  17. brokenm

    brokenm

    Joined:
    Aug 28, 2014
    Posts:
    22
    honor0102, ShayneDsouza and Degree like this.
  18. Degree

    Degree

    Joined:
    Nov 8, 2014
    Posts:
    2
  19. Emre_Kor

    Emre_Kor

    Joined:
    May 14, 2020
    Posts:
    1
    thank you. ıt is work :)
     
  20. hasanugr

    hasanugr

    Joined:
    Jan 16, 2020
    Posts:
    1
    I was facing this problem too and my solution was as follows;
    Assets -> Reimport All (Wait a few minutes)
    My problem fixed with that way, i hope it will help to you too.
     
    Ubrix99 and onlyonemanstudio like this.
  21. Blobux

    Blobux

    Joined:
    Aug 11, 2020
    Posts:
    3
  22. deltagaming323

    deltagaming323

    Joined:
    Mar 19, 2020
    Posts:
    1
    Thank you so much ,this Worked for me
     
  23. Abdelkarim_taliane

    Abdelkarim_taliane

    Joined:
    May 13, 2021
    Posts:
    2
    I faced the same issue, but this package version works for me, thanks, man! :)
     
    meshak2002 likes this.
  24. onlyonemanstudio

    onlyonemanstudio

    Joined:
    Dec 4, 2020
    Posts:
    1
    It works! So simple :)
     
  25. pradeeppurigoswami7

    pradeeppurigoswami7

    Joined:
    Jan 25, 2021
    Posts:
    1
    https://developers.google.com/admob/unity/rewarded
    Check the Webpage so all problem is solve.

    Example:-
    using GoogleMobileAds.Api;
    ...
    public class GoogleMobileAdsDemoScript : MonoBehaviour
    {
    private RewardedAd rewardedAd;
    ...

    public void Start()
    {
    string adUnitId;
    #if UNITY_ANDROID
    adUnitId = "ca-app-pub-3940256099942544/5224354917";
    #elif UNITY_IPHONE
    adUnitId = "ca-app-pub-3940256099942544/1712485313";
    #else
    adUnitId = "unexpected_platform";
    #endif

    this.rewardedAd = new RewardedAd(adUnitId);

    // Called when an ad request has successfully loaded.
    this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
    // Called when an ad request failed to load.
    this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
    // Called when an ad is shown.
    this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
    // Called when an ad request failed to show.
    this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
    // Called when the user should be rewarded for interacting with the ad.
    this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
    // Called when the ad is closed.
    this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the rewarded ad with the request.
    this.rewardedAd.LoadAd(request);
    }

    public void HandleRewardedAdLoaded(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardedAdLoaded event received");
    }

    public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
    MonoBehaviour.print(
    "HandleRewardedAdFailedToLoad event received with message: "
    + args.Message);
    }

    public void HandleRewardedAdOpening(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardedAdOpening event received");
    }

    public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
    {
    MonoBehaviour.print(
    "HandleRewardedAdFailedToShow event received with message: "
    + args.Message);
    }

    public void HandleRewardedAdClosed(object sender, EventArgs args)
    {
    MonoBehaviour.print("HandleRewardedAdClosed event received");
    }

    public void HandleUserEarnedReward(object sender, Reward args)
    {
    string type = args.Type;
    double amount = args.Amount;
    MonoBehaviour.print(
    "HandleRewardedAdRewarded event received for "
    + amount.ToString() + " " + type);
    }
    }

    The OnUserEarnedReward event provides special event arguments. It passes an instance of Reward with a Type and Amount describing the reward given to the user:

    public void HandleUserEarnedReward(object sender, Reward args)
    {
    string type = args.Type;
    double amount = args.Amount;
    MonoBehaviour.print(
    "HandleRewardedAdRewarded event received for "
    + amount.ToString() + " " + type);
    }
     
  26. ysndrkyl

    ysndrkyl

    Joined:
    Apr 28, 2022
    Posts:
    1
    thx my friend =)
     
  27. Gausroth

    Gausroth

    Joined:
    Jun 13, 2020
    Posts:
    3
    This fixed it for me as well. After looking at all of the packages that came after this one, they seem to be missing most of the scripts.