I have this in my main xml file:
A lot of people Migrating existing applications to the google play services method are incorrectly adding the wrong information.
Something that I would like to point out is that many people with the same question have been using this as a template
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="50dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX"
ads:loadAdOnCreate="true" >
</com.google.android.gms.ads.AdView>
This is incorrect as xmlns:ads should be change to:-
xmlns:ads="http://schemas.android.com/apk/res-auto"
Like so
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="50dp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX"
ads:loadAdOnCreate="true" >
</com.google.android.gms.ads.AdView>
I faced that same problem because i do not add this line on xmlns:ads="http://schemas.android.com/apk/res-auto" top of . Then i change my xml code like this
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintTop_toTopOf="parent"
ads:layout_constraintBottom_toTopOf="@+id/headerText"
android:layout_marginTop="@dimen/_2sdp"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
android:visibility="visible">
</com.google.android.gms.ads.AdView>
after that i add this 3 line in onCreate method
AdView mAdView = (AdView)findViewById(R.id.adView);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);