idbrii
idbrii

Reputation: 11946

How to get Google's example code working for AdMob 4.1.0 using an Android device

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:

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

What am I doing wrong?

Upvotes: 2

Views: 7331

Answers (1)

idbrii
idbrii

Reputation: 11946

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.

Upvotes: 3

Related Questions