2

Assets:

  1. Unity 2018.4.30f1

  2. GoogleMobileAds-v5.4.0.unitypackage plugin

  3. Enable In GoogleMobileAdsSettings - GoogleAdMob and I Added the App Id to Android and IOS

adbanner.cs script

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

public class AdBanner : MonoBehaviour
{

    private BannerView bannerView;
    private string idApp, idBanner;

    public void Start()
    {
        idApp = "ca-app-pub-2584265330622657~8465399911";
        idBanner = "ca-app-pub-2584265330622657/1877307815";

        MobileAds.Initialize(idApp);
        RequestBannerAd();
    }

    public void RequestBannerAd()
    {
        bannerView = new BannerView(idBanner, AdSize.Banner, AdPosition.Bottom);
        AdRequest request = AdRequestBuild();
        bannerView.LoadAd(request);
    }

    AdRequest AdRequestBuild()
    {
        return new AdRequest.Builder().Build();
    }

}


I have this error that does not allow me to build the application further for xcode

The all errors :

You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all UnityEngine.MonoBehaviour:.ctor() ButtonBehaviour:.ctor() GoogleMobileAds.Unity.BannerClient:CreateButtonBehavior() (at Assets/GoogleMobileAds/Platforms/Unity/BannerClient.cs:64) GoogleMobileAds.Unity.BannerClient:ShowBannerView() (at Assets/GoogleMobileAds/Platforms/Unity/BannerClient.cs:143) GoogleMobileAds.Unity.BannerClient:LoadAd(AdRequest) (at Assets/GoogleMobileAds/Platforms/Unity/BannerClient.cs:123) GoogleMobileAds.Api.BannerView:LoadAd(AdRequest) (at Assets/GoogleMobileAds/Api/BannerView.cs:61) AdBanner:RequestBannerAd() (at Assets/Scripts/AdBanner.cs:25) AdBanner:Start() (at Assets/Scripts/AdBanner.cs:18)

  • For which line is this thrown? – derHugo Jan 29 '21 at 13:13
  • He says for line 18 – Cristian Ilisei Jan 29 '21 at 13:15
  • Please add the complete error message including stack trace to your question. Also point out via a comment which line this is in your code snippet ;) nobody here wants to be counting lines ^^ – derHugo Jan 29 '21 at 13:16
  • Are you sure this is the reason why you can't build your app ^^ It's a runtime warning not a compiler error ... none of the Google adds classes seem to be `MonoBehaviour` though so the question is where exactly the code tries to create a `MonoBehaviour` using `new` – derHugo Jan 29 '21 at 13:17
  • @derHugo it seems that [here](https://github.com/googleads/googleads-mobile-unity/blob/master/source/plugin/Assets/GoogleMobileAds/Platforms/Unity/BannerClient.cs#L64), `ButtonBehaviour` is a `MonoBehaviour`. – Guru Stron Jan 29 '21 at 13:23
  • @GuruStron yup that was the method I didn't find at first thanks ^^ .. and yep that is stupid by Google Ads ^^ – derHugo Jan 29 '21 at 13:24
  • 2
    Just FYI submitted an [issue](https://github.com/googleads/googleads-mobile-unity/issues/1562). – Guru Stron Jan 29 '21 at 13:25
  • 'GoogleMobileAds/GoogleMobileAds.h' file not found in xcode – Cristian Ilisei Jan 29 '21 at 13:35

0 Answers0