Xamarin.Forms - 'Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

Ganesh Gebhard 366 Reputation points
2021-05-09T23:10:05.63+00:00

Hey!

I have an app in Xamarin.Forms (Android & iOS), but this only concerns the Android part.

I want to add Google ads to my app, but I get an error which I cannot place. I'm using this tutorial: https://www.c-sharpcorner.com/article/google-admob-display-ads-in-xamarin-forms/

As soon I deploy the app on my physical device, the app starts but after a few seconds it crashes because of this error:

95028-image.png

Does someone know the solution for this issue?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CherryBu-MSFT 326 Reputation points
    2021-05-10T02:54:47.843+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    From this article Update your AndroidManifest.xml, add your application ID to your app's AndroidManifest.xml file by adding a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID", as shown below.

    <application android:label="googleads.Android" android:theme="@style/MainTheme">  
        <meta-data  
                 android:name="com.google.android.gms.ads.APPLICATION_ID"  
                 android:value="ca-app-pub-3729926965359663~5196436184"/>  
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />  
      </application>  
    

    Update:
    Install MarcTron.Admob firstly, then using test ad unit Id to test admob ads.

     <controls:MTAdView x:Name="myAds" AdsId="{OnPlatform Android='ca-app-pub-3940256099942544/6300978111', iOS='ca-app-pub-3940256099942544/2934735716'}" />  
    

    If the Banners don't appear in your app, probably it's a size problem. To solve it, add this style in your ContentPage.Resources or app.xaml:

    <ContentPage.Resources>  
            <Style TargetType="controls:MTAdView">  
                <Setter Property="HeightRequest">  
                    <Setter.Value>  
                        <x:OnIdiom Phone="50" Tablet="90" />  
                    </Setter.Value>  
                </Setter>  
            </Style>  
        </ContentPage.Resources>  
    

    95573-image-10.png

    more detailed note that you can take a look:
    https://stackoverflow.com/questions/60470603/why-admob-doesnt-appear-in-xamarin-forms

    Best Regards,
    Cherry Bu
    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.