Required XML attribute "adSize" was missing

844 views
Skip to first unread message

Paul Falstad

unread,
Jun 6, 2014, 2:47:58 PM6/6/14
to google-adm...@googlegroups.com

I'm getting a message "Required XML attribute adSize was missing" at runtime when I try to create an ad.

In the XML file I'm doing:


     <com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
         
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:paddingTop="3dp"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         />                 

In the code I'm doing:
 

adv.setAdSize(AdSize.BANNER); 
adv.setAdUnitId("ad unit id");
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) vg.getLayoutParams();
params.width = 320;
params.height = 50;
vg.setLayoutParams(params);
        AdRequest adRequest = new AdRequest.Builder()
         .build();
         adv.loadAd(adRequest);
 
I cannot set the ad size in the XML file because it needs to be set programmatically depending on the size of the window.  I can't use smart banners because they don't work with mediation.

Do I have to create the AdView programmatically instead of doing it in XML?

Eric Leichtenschlag

unread,
Jun 6, 2014, 8:54:05 PM6/6/14
to google-adm...@googlegroups.com
You must have added the googe-play-services.jar into your project instead of referencing google-play-services_lib/ as a library project in your workspace. If you don't reference the full library project, you're missing the res/values/ads_attrs.xml file from the google-play-services_lib where the adSize attribute is defined.

Thanks,
Eric

Paul Falstad

unread,
Jun 6, 2014, 9:36:05 PM6/6/14
to google-adm...@googlegroups.com
Hi,

I don't think so, it looks like I am referencing it as a library project and do not have google-play-services.jar in my libs directory.  Note that I am not trying to use the adSize xml attribute.  I can't use it because I need to set the ad size at run time.  I'm trying to use setAdSize() to set the size of the AdView.

Eric Leichtenschlag

unread,
Jun 9, 2014, 4:26:41 PM6/9/14
to google-adm...@googlegroups.com
Sorry, I read your question wrong the first time.

Yeah, you'll need to define your AdView in code if you're setting the ad size at runtime. When defining an AdView in XML, ads:adSize and ads:adUnitId are required attributes.

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages