Reputation: 912
I am trying to include ads in my test app, when I run the app in an emulator or a device I get a banner add saying Required XML attribute “adSize” was missing
.
I have set xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
in com.google.android.gms.ads.AdView
tag.
Not sure how to resolve this issue.
More details : Android Studio AI-141.1989493
Code snippet :
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId("ca-app-pub-xxxxx/xxxxxx");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("E58D5904AA50D88E2FD63A1D1EF97B34")
.build();
mAdView.loadAd(adRequest);
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Activity_main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayout01">
<TableRow android:id="@+id/LinearLayout0">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxx/xxxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34">
</com.google.android.gms.ads.AdView>
Upvotes: 0
Views: 2132
Reputation: 123
The code below worked for me, and I think it will be all round :
<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"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Upvotes: 0
Reputation: 162
<TableRow
android:id="@+id/LinearLayout0"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxx/xxxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34">
</com.google.android.gms.ads.AdView>
</TableRow>
try this include a property on your root as done here.
Upvotes: 0
Reputation: 7927
Change:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
To:
xmlns:ads="http://schemas.android.com/apk/res-auto"
Upvotes: 6