2
votes

I want to use xml to add a banner ad to my app. To understand how to do this, I read through the Google AdMob Ads Android Banner XML tutorial. There's even example code. However, the example project doesn't display ads on my device (a Motorola xt720). I get nothing relevant in LogCat.

If I go to project settings and remove the 4.0.4 jar and add the 4.1.0 jar that I downloaded with Android SDK and AVD Manager (downloaded "Google Admob Ads Sdk package, revision 2" and the file is android-sdk-linux_86/extras/google/admob_ads_sdk/GoogleAdMobAdsSdk-4.1.0.jar), then I get this in LogCat.

ERROR/Ads(4486): AdView missing required XML attribute "adSize".

INFO/Ads(4486): To get test ads on this device, call adRequest.addTestDevice("00000000000000000000000000000000");

I make that change:

    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice("00000000000000000000000000000000");
    adView.loadAd(adRequest);

And now I get this:

ERROR/Ads(5018): AdView missing required XML attribute "adSize".

WARN/Ads(5018): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?

INFO/Ads(5018): onFailedToReceiveAd(Invalid Google Ad request.)

If I edit main.xml to fix the ads:adUnitId to be the value I have in my admob account, I still get the same error. As you can see, I am setting my adSize:

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="000000000000000"
    ads:adSize="BANNER" />

So in summary:

  • I fixed the library version
  • I added my test device
  • I set my ads:adUnitId

But I still get AdView missing required XML attribute "adSize"

What am I doing wrong?

1
To be clear: I already knew the answer when I asked this question. I found that most of the other similar questions on SO were specific to the user (they posted their code and got comments on that) instead of something general to all. If someone could make this community-wiki so it can be updated for the next version of admob, that would be great!idbrii

1 Answers

3
votes

There are some changes to the way Admob works in version 4.1.0

There's a discussion on Google Groups about this issue and how they haven't updated the documentation.

Google employee Tim posted:

1) Remove attrs.xml (or if you need it for your own custom attributes, remove the parts related to AdViews).

2) Change the namespace in your layout from xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename" to xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Once you have made those two changes (along with the other changes you already made), you should now see an ad.