Ad Size and Ad unit id must be set before loadAd is called

I found solution in the github example, that is:

instead of

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

delete the xmlns:ads*** tag and add

xmlns:ads="http://schemas.android.com/apk/res-auto"

tag to your LinearLayout tag as follow:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
<TextView android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="@string/hello"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       ads:adSize="BANNER"
                       ads:adUnitId="INSERT_YOUR_AD_UNIT_ID_HERE"/>
</LinearLayout>

That's it :)

github link for this xml


Warning: Make sure you set the ad size and ad unit ID in the same manner (i.e. set both in XML or both programmatically).

https://developers.google.com/admob/android/banner