Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required XML attribute "adSize" was missing

Tags:

android

admob

I get a "Required XML attribute "adSize" was missing" when I launch my app. This is written on the screen of my smartphone instead of my banner.

I tried the different solutions founded on stack (like xmlns:ads="http://schemas.android.com/apk/res-auto" instead of xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads" or instead of xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads") but it doesn't work.

Here's my java code (a simple Hello World just to try to implement a banner):

package com.example.publicite;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

Here's my xml file:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="MyAdUnitId"
    ads:loadAdOnCreate="true"
    ads:testDevices="TEST_EMULATOR" />

<Button
    android:id="@+id/votrescore"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="..." />

</RelativeLayout>

and here's my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.publicite"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="13"
    android:targetSdkVersion="13" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>

    <activity
        android:name="com.example.publicite.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

 </manifest>

I use the google play service lib.

like image 696
Glork Avatar asked Mar 26 '14 21:03

Glork


Video Answer


4 Answers

Try changing your declaration this way:

<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="wrap_content"
    ads:adUnitId="YOUR_AD_UNIT_ID"
    ads:adSize="BANNER"/>

---- EDIT ----

You can also try to do it programmatically. Simply, instead of an AdView layout item, define a LinearLayout and by code do something like this:

final AdView adView = new AdView(getActivity());
adView.setAdUnitId("YourId");
adView.setAdSize(AdSize.BANNER);

final LinearLayout adLinLay = (LinearLayout) view.findViewById(R.id.your_defined_linearlayout);
adLinLay.addView(adView);

final AdRequest.Builder adReq = new AdRequest.Builder();
final AdRequest adRequest = adReq.build();
adView.loadAd(adRequest);
like image 141
nKn Avatar answered Oct 02 '22 01:10

nKn


Here is a weird answer. I just restarted my eclipse and it stared working. This might help some one.

Just restart eclipse, android studio or IntelliJ IDE

like image 24
zizutg Avatar answered Oct 02 '22 00:10

zizutg


I have same problem.

Solution for me:

 xmlns:ads=""

changed to

xmlns:ads="http://schemas.android.com/apk/res-auto"
like image 8
ketom Avatar answered Oct 02 '22 01:10

ketom


Problem fixed for me by changing name space uri

from

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

to

xmlns:ads="http://schemas.android.com/apk/res-auto"
like image 7
kartikag01 Avatar answered Oct 01 '22 23:10

kartikag01