Monogame With Xamarin or Maui (IOS /Android)

thank you for the answer

no I don’t necessarily want to use the marcojack library
i just want it to work
I tried to integrate Xamarin.GooglePlayServices.Ads.Lite
without the library I received these error messages
I’m at the stage I just want to integrate this dependency without errors but without success I don’t know why I have the messages I sent above

Here is a barebones Android example that builds without issue. Create a fresh Android MG 3.8.1 project named “Project1”, then replace these 2 files.

Project1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-android</TargetFramework>
    <SupportedOSPlatformVersion>23</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <ApplicationId>com.companyname.Project1</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
    <UseMauiEssentials>true</UseMauiEssentials>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MonoGame.Framework.Android" Version="3.8.1.303" />
    <PackageReference Include="Xamarin.GooglePlayServices.Ads.Lite" Version="121.2.0" />
  </ItemGroup>
</Project>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Project1.Project1" android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="31" />
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
  <application android:label="Project1">
    <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713" />
  </application>
</manifest>

Note: the APPLICATION_ID provided here is just the test ID. If you cannot build this: run Build > Clean in VS, close VS, delete your obj and bin folders, restart VS, and try again. If you still cannot build, there is something wrong with your dev stack.

1 Like

great thank you :+1:

I will test this and get back to you

thanks again

I don’t know what this means

sorry
it is a mistakeI wanted to sayI have to add <UseMauiEssentials>true</UseMauiEssentials> ?

I added Maui Essential I didn’t get any errors I’m satisfied
now i tried something like this in Activity1.cs

InterstitialAd.Load(Game1.Activity, "ca-app-pub-3940256099942544~3347511713",
               new AdRequest.Builder().Build(), new InterstitialCallbackInherit());

I managed to add a simple banner finally
Thanks a lot :+1: :grinning:
I based myself on an old class that I found on the forum it makes simple banners work, however the full page does not work for the moment

I used this class if it helps

using System;

using Android.Gms.Ads;
using Android.Gms.Ads.Interstitial;
using Android.Views;
using Android.Widget;


namespace Project1.Publicity
{
    public static class AdController
    {
        public static InterstitialAd interstitialHandle = null;
        public static AdView AdView = null;

        public static event EventHandler AdClosed;

        // AD ID's This is a test use yours from Admob
        public static string adID1 = "Your ID"; // standard full page ad
        public static string adID3 = "Your ID"; // banner ad

        public static bool adRegularLoaded = false;
        public static bool adBannerLoaded = false;

        public static void InitBannerAd(FrameLayout fl)
        {
            LinearLayout ll = new LinearLayout((Activity1)Game1.Activity)
            {
                Orientation = Orientation.Horizontal
            };

            ll.SetGravity(GravityFlags.CenterHorizontal | GravityFlags.Bottom);

            MobileAds.Initialize(Game1.Activity);

            AdView = new AdView((Activity1)Game1.Activity)
            {
               AdUnitId = adID3,
               // AdUnitId = adID1,
                // AdSize = AdSize.Banner //full
                //AdSize = AdSize.FullBanner //full
                AdSize = AdSize.FullBanner //full
            };

            ListeningBanner listening = new ListeningBanner();

            AdView.AdListener = listening;
            AdView.LoadAd(new AdRequest.Builder().Build());
            AdView.Visibility = ViewStates.Visible;

            ll.AddView(AdView);
            fl.AddView(ll);
        }


        private static void Listening_AdClosed(object sender, EventArgs e)
        {
            AdClosed?.Invoke(null, null);
        }


    }
    
    internal class ListeningRegular : AdListener
    {
        public event EventHandler AdClosed;

        public override void OnAdLoaded()
        {
            AdController.adRegularLoaded = true;
            base.OnAdLoaded();
        }

        public override void OnAdClosed()
        {
            //AdController.interstitialHandle.LoadAd(new AdRequest.Builder().Build());
           // AdClosed?.Invoke(this, null);
            base.OnAdClosed();
        }
        public override void OnAdOpened()
        {
            base.OnAdOpened();
        }
    }

    internal class ListeningBanner : AdListener
    {
        public override void OnAdFailedToLoad(LoadAdError p0)
        {
            base.OnAdFailedToLoad(p0);
        }

        public override void OnAdLoaded()
        {
            AdController.adBannerLoaded = true;
            base.OnAdLoaded();
        }

        public override void OnAdClosed()
        {
            AdController.AdView.LoadAd(new AdRequest.Builder().Build());
            base.OnAdClosed();
        }
    }
}

In Activity1.cs

    public class Activity1 : AndroidGameActivity
    {
        private Game1 _game;
        private View _view;

        private FrameLayout fl;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _game = new Game1();
          // _view = _game.Services.GetService(typeof(View)) as View;
         
            fl = new FrameLayout(this);
            fl.AddView((View)_game.Services.GetService(typeof(View)));

            AdController.InitBannerAd(fl);

            SetContentView(fl);
            //SetContentView(_view);
            _game.Run();
        }

    }


}
1 Like

I don’t know if this method is still valid or are we limited only with banners?

Thanks The Kelsam
I want to reward you for your help

1 Like

I think it says limits on thr GitHub… might be one of them…that’s why I was waiting for him to fix it…I only wanted full page interstitial