Required XML attribute "adSize" was missing.

10,322 views
Skip to first unread message

glova...@gmail.com

unread,
Nov 5, 2013, 9:56:43 AM11/5/13
to google-adm...@googlegroups.com
Hi,
I have my app live in Google Play. In it I've used "GoogleAdMobAdsSdk-6.4.1.jar" and all works fine.
 
I am trying to include Google+ API in my app. From various posts I found that standalone AdMob jar is now obsolete and I have to use "com.google.android.gms.ads" instead. Here is my layout:
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="MY_AD_UNIT_ID"
                ads:loadAdOnCreate="false"
                android:visibility="visible" />
   
</LinearLayout>
 
I removed the standalone AdMob JAR and using the AdMob library form Google Play Services library. However this configuration is showing "Required XML attribute "adSize" was missing." error message on the designer and at runtime. Any help would be much appreciated.
Regards.
admob banner design.png

Amy Quispe (AdMob SDK Team)

unread,
Nov 5, 2013, 5:51:14 PM11/5/13
to google-adm...@googlegroups.com
Hi there,

Instead of using the XML namespace "http://schemas.android.com/apk/lib/com.google.android.gms.ads", use "http://schemas.android.com/apk/res-auto". Sorry that change is unintuitive!

Hope this helps.

Amy

glova...@gmail.com

unread,
Nov 6, 2013, 5:56:28 AM11/6/13
to google-adm...@googlegroups.com
Thank you Amy. That fixed the issue. Appreciate your help.
Message has been deleted

Seshu Saragadam

unread,
Jan 19, 2014, 4:00:51 AM1/19/14
to google-adm...@googlegroups.com
Hi Amy,
     I replace with xml namespace with "http://schemas.android.com/apk/res-auto" even-though its showing required xml attribute adsize was missing. can i know the reason and also when i run the application the emulator its successfully showing the default add in emulator but not showing ads. please look on the attached screen shot.

Thanks and Regard,
S.Seshu
s.ses...@gmail.com


On Wednesday, November 6, 2013 4:21:14 AM UTC+5:30, Amy Quispe (AdMob SDK Team) wrote:
banner.png

Amy Quispe (AdMob SDK Team)

unread,
Jan 22, 2014, 4:42:09 PM1/22/14
to google-adm...@googlegroups.com
Hi Seshu,

The screenshot looks fine. What seems to be the problem?

Amy Quispe

Carlo Moretti

unread,
Jan 24, 2014, 9:48:26 AM1/24/14
to google-adm...@googlegroups.com
Hi Amy, i tried with the new http://schemas.android.com/apk/res-auto to solve the "Required XML attribute "adSize"" problem, but now Eclipse says "error: No resource identifier found for attribute 'loadAdOnCreate' in package...", and if i remove it i don't see ads... actually i have never been able to see ads in a whole day of trials!! Please help! 

Amy Quispe (AdMob SDK Team)

unread,
Jan 24, 2014, 7:02:56 PM1/24/14
to google-adm...@googlegroups.com
Hi Carlo,

In the new GPS the "loadAdOnCreate" attribute doesn't exist anymore. You'll need to load the ad in the code instead. If you check out our migration guide and look at the "Creating AdView in XML and loading an ad" row you can see how this has changed between the two versions.

Hope this helps!

Amy Quispe

Carlo Moretti

unread,
Jan 25, 2014, 5:29:32 AM1/25/14
to google-adm...@googlegroups.com
Amy, thank you for your quick reply!!
But, i really think this is not a great improvement, as we cannot insert banners through XML-only anymore.
The need of using java code is uncomfortable when managing different versions (i.e using libraries for free and paid versions, i need to duplicate and manage more java code, that were unnecessary in old XML-only way...)

Anyway now app is running, although i cannot see banners yet (logcat: No fill from ad server. Failed to load ad: 3), but i'm afraid i just have to wait to see it working, right?

BTW, is it a good pratice to nest an adView.loadAd(adRequest) call inside an AdListener().onAdFailedToLoad() method?

thanx again for the quick and clear answer!

c.

Amy Quispe (AdMob SDK Team)

unread,
Jan 27, 2014, 7:20:57 PM1/27/14
to google-adm...@googlegroups.com
Hi Carlo,

Why are trying to load the adRequest if the AdFailedToLoad?

Amy Quispe

Carlo Moretti

unread,
Jan 28, 2014, 4:04:22 AM1/28/14
to google-adm...@googlegroups.com
Hi, Amy, well i didn't know how it works, now i've seen it will automatically retry loading ads after 60secs, that's ok.
Now i've got another problem: on devices and emulators with language set to English at last i can see ads (both in test and real mode), but on devices with language set to Italian ads won't load returning "failed to load ad: 3".
Do i need to enable something somewhere?
I cannot find anything out there about languages!

Amy Quispe (AdMob SDK Team)

unread,
Jan 30, 2014, 9:42:10 PM1/30/14
to google-adm...@googlegroups.com
Hi Carlo,

There are language settings in the admob interface.

Amy Quispe

Carlo Moretti

unread,
Feb 3, 2014, 4:14:44 AM2/3/14
to google-adm...@googlegroups.com
Hi Amy!
... sorry, cannot see language settings anywhere... do you mean the admob consolle? Should i create a mediation?
Actually to see banners on devices with language set to italian i just had to wait for 4 days (that is a long time to see if it works!!), and i still don't see test banners, while interstitials are ok, both with real ads and test ones.
Message has been deleted

Danny Apps

unread,
Mar 16, 2014, 10:50:48 AM3/16/14
to google-adm...@googlegroups.com
Hi Amy, I had the same problem like Giovantech had (adSize was missing). Now it looks good on the xml preview in eclipse but i can't run the project due the error: No resource identifier found for attribute 'loadAdOnCreate' in package  (com.mypackage) 
Any suggestion what i could do? Thank you.

Amy Quispe (AdMob SDK Team)

unread,
Mar 17, 2014, 6:54:59 PM3/17/14
to google-adm...@googlegroups.com
Hi Danny,

Are you using the legacy SDK or the Google Play Services version? loadAdOnCreate was deprecated in the Google Play Services version, so you'll have to load the ad from the code.

Amy Quispe

robert abraham

unread,
May 7, 2014, 10:00:45 AM5/7/14
to google-adm...@googlegroups.com
Hello there,

I too am having problem with the new google mobile ads. I'm having error in the xml, "Required XML attribute "adSize" was missing. These are my codes:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    

    <!-- Screen Design for Photos -->

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="15dip"
        android:text="PILIH Gong"
        android:textSize="18dip" />

   <LinearLayout 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout2" 
    android:layout_width="fill_parent" 
    android:paddingTop="30px">
    
    <Button 
        android:id="@+id/button1" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="3" 
        android:text="Sasalakan" 
        android:onClick="clickHandler"></Button>
    <Button 
        android:id="@+id/button2" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="3.0" 
        android:text="Nananangon" 
        android:onClick="clickHandler"></Button>
    <Button 
        android:id="@+id/button3" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="3.0" 
        android:text="Hahambaton" android:onClick="clickHandler"></Button>
</LinearLayout>

   <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-1812703940655513/5200925381"/>

<LinearLayout 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout3" 
    android:layout_width="fill_parent" 
    android:paddingTop="30px">
    
    <Button 
        android:layout_width="fill_parent" 
        android:layout_weight="3" 
        android:layout_height="wrap_content" 
        android:id="@+id/button4" 
        android:text="Hohotukon" 
        android:onClick="clickHandler"></Button>
    <Button 
        android:layout_width="fill_parent" 
        android:layout_weight="3.0" 
        android:layout_height="wrap_content" 
        android:id="@+id/button5" 
        android:text="Kukulimpoon" 
        android:onClick="clickHandler"></Button>
    <Button 
        android:layout_width="fill_parent" 
        android:layout_weight="3.0" 
        android:layout_height="wrap_content" 
        android:id="@+id/button6" 
        android:text="Tatavag" 
        android:onClick="clickHandler"></Button>
    
   
</LinearLayout>

 

</LinearLayout>

Meanwhile the code for java are:

package my.androidpreneur.gong;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Maingong extends Activity {
private AdView mAdView;
    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maingong);
        
        
       
        mAdView.setAdListener(new ToastAdListener(this));
        
        AdView mAdView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("TEST_DEVICE_ID")
            .build();
        mAdView.loadAd(adRequest);
        
        
     
       
        
        Button b1 = (Button) findViewById(R.id.button1);
        Button b2 = (Button) findViewById(R.id.button2);
        Button b3 = (Button) findViewById(R.id.button3);
        Button b4 = (Button) findViewById(R.id.button4);
        Button b5 = (Button) findViewById(R.id.button5);
        Button b6 = (Button) findViewById(R.id.button6);
        
        b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent1 = new Intent(Maingong.this, Sasalakon1.class);
startActivity(intent1);
}
});
        
        b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent2 = new Intent(Maingong.this, Nananangon2.class);
startActivity(intent2);
}
});
        
        b3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent3 = new Intent(Maingong.this, Hahambaton3.class);
startActivity(intent3);
}
});
        
        b4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent4 = new Intent(Maingong.this, Hohotukon4.class);
startActivity(intent4);
}
});
        
        b5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent5 = new Intent(Maingong.this, Kukulimpoon5.class);
startActivity(intent5);
}
});
        
        b6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent6 = new Intent(Maingong.this, Tatavag6.class);
startActivity(intent6);
}
});
    }
    
    @Override
protected void onPause(){
    mAdView.pause();
    super.onPause();
    }
    
    @Override
protected void onResume(){
    super.onResume();
    mAdView.resume();
    }
    
    @Override
protected void onDestroy(){
    mAdView.destroy();
    super.onDestroy();
    }
}

Thank you in advance.

Amy Quispe (AdMob SDK Team)

unread,
May 8, 2014, 5:36:00 PM5/8/14
to google-adm...@googlegroups.com
Hi there Robert,

Does this problem go away if you remove the AdSize from the XML and set it in the code? - mAdView.setAdSize(AdSize.BANNER)

Amy Quispe

van anh pham

unread,
Feb 5, 2015, 10:54:57 AM2/5/15
to google-adm...@googlegroups.com
Hello,
here is my code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button 
            android:id="@+id/btn_previous"
            android:background="@drawable/arrow_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="PreviousDay"
            android:layout_gravity="bottom|left"/>
        <Button 
            android:id="@+id/btn_next_day"
            android:background="@drawable/arrow_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="NextDay"
            android:layout_gravity="bottom|right"/>
    </LinearLayout>
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        ads:adUnitId="@string/banner_ad_unit_id"/>
   
</LinearLayout>
</ScrollView>
and in code java:
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.result_layout);
      
     mAdView = (AdView) findViewById(R.id.adView);
  mAdView.setAdSize(AdSize.BANNER);
  mAdView.setAdUnitId(getResources().getString(R.string.banner_ad_unit_id));
  
  AdRequest adRequest = new AdRequest.Builder()
   .addTestDevice("E1D6B44CB851F4F5AA235A18F00EC121")
   .build();
       mAdView.loadAd(adRequest);

  }
but the issue("Required XML attribute "adSize" was missing.") was not fixed. please help me. I use google-play-services_lib.
thank you so much!

Eric Leichtenschlag (Mobile Ads SDK Team)

unread,
Feb 6, 2015, 3:31:50 PM2/6/15
to google-adm...@googlegroups.com
Hello,

When you create an AdView in XML, you need to specify the adSize in XML as well: 

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        ads:adUnitId="@string/banner_ad_unit_id"
        ads:adSize="BANNER"/>

Then you can remove the setAdSize method in code. I've commented it out below.

protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.result_layout);
      
      mAdView = (AdView) findViewById(R.id.adView);
   // mAdView.setAdSize(AdSize.BANNER);
   mAdView.setAdUnitId(getResources().getString(R.string.banner_ad_unit_id));
   
   AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice("E1D6B44CB851F4F5AA235A18F00EC121")
    .build();
        mAdView.loadAd(adRequest);

   }

Thanks,
Eric

arsamd...@gmail.com

unread,
Mar 10, 2016, 7:24:34 PM3/10/16
to Google Mobile Ads SDK Developers
This was Awesome , Thanks , Saved many time , 

Juanma Perez

unread,
Feb 1, 2017, 5:04:38 PM2/1/17
to Google Mobile Ads SDK Developers
Hi Amy, my code XML is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/tools"
android:orientation="vertical"
    android:layout_width="match_parent"
android:layout_height="match_parent">

    <com.google.android.gms.ads.AdView
android:id="@+id/adView"
        android:layout_width="match_parent"
android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
        ads:adUnitId="@string/banner_ad_unit_id"
ads:adSize="BANNER" />
 Is the same mistake, adSize was missing.

Ivan Bautista (Mobile Ads SDK Team)

unread,
Feb 1, 2017, 9:39:52 PM2/1/17
to Google Mobile Ads SDK Developers
Hi Juanma,

Based from your code, you interchanged the value of the xml namespaces "app" and "ads". 

Try using below code instead inside the LinearLayout XML tag. Also, you don't need to include the "app" namespace if you're not going to use any of its attributes in the parent layout's child views:  
xmlns:ads="http://schemas.android.com/apk/res-auto"

Also, since this thread is almost a year ago, I suggest that you open a new thread and from there we can continue with the investigation.

Thanks,
Ivan Bautista
Mobile Ads SDK Team 
Reply all
Reply to author
Forward
0 new messages