0

My application was working with android 4.2 and using Admob x.x.x.jar file few days back. i just configured android sdk 4.4 and i noticed Google play ads are not longer working, also found it should be upgraded as well so what i did following:

Before My XML Was:

<com.google.android.gms.ads.AdView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center"
            ads:adSize="BANNER"
            ads:adUnitId="asdadadasddas"
            />

Today I updated it

<com.google.android.gms.ads.AdView android:id="@+id/adView"
             xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       ads:adUnitId="asdadadasddas"
                       ads:adSize="BANNER"
                       />

My Manifest

 <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

values => Integer.xml

<integer name="google_play_services_version">5089034</integer>

and it give me following error enter image description here

Note: I am not using any java code to display it is that necessary?

any help would be appreciated.

UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278

3 Answers3

1

I appreciate answers of all developers actually i solved this problem by combining the answers of all so i would like to enter steps here that might help others.

XML Layout:

 <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="ca-app-pub-***" 
            ads:adSize="BANNER"
                       />

Two mistakes in my code were: 1) xmlns:ads value was wrong & this mistake pointed out by donfuxx 2) i was using old AdUnitId with following format: a15220c7a5f3775 but in latest AdMob its format is entirely different as used in above example.

Note: If you use old "ads:adUnitId" it will show blank ad and this was the case with me.

Javacode Java code is also required

AdRequest adRequest = new AdRequest.Builder()
        .build();
        AdView adView = (AdView) view.findViewById(R.id.adView);
        adView.loadAd(adRequest);

Then again i found another error: Class not found exception although i had imported the Google Play project in my application. Then i found an article in which it was mentioned copy Google Play Jar inside your "libs" folder and it will be automatically included in your android private libraries to resolve this issue.

Final Issue No need to put value in integer.xml inside your app because when you include Google play services project inside your app, it will automatically pick version value out of it in your manifest file.

So these were the issues i faced during migration of adMob and will help others to implement it quickly.

RyPope
  • 2,645
  • 27
  • 51
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
0

You should no longer be setting your adUnitId/adSize in the layout. Instead do:

adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);

Layout:

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

And finally,

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("XXXXXXXXXXXXXXXXXXXX")
.build();
adView.loadAd(adRequest);
RyPope
  • 2,645
  • 27
  • 51
  • i appreciate it, what should be the addTestDevice value? – UMAR-MOBITSOLUTIONS Sep 08 '14 at 17:50
  • You could remove it, or find the device ID using something like [this](http://stackoverflow.com/questions/9681400/android-get-device-id-for-admob). It basically just doesn't send ad requests if it's a test device. – RyPope Sep 08 '14 at 17:52
  • Try the updated code. Also add "xmlns:ads="http://schemas.android.com/apk/res-auto"" to the layout that contains it. This document is a good one to follow. https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner – RyPope Sep 09 '14 at 16:37
0

You can still use ads:adSize xml attribute!

However, your xml namespace setting is wrong in the adview element, because it refers to the legacy admob:

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

but since you already use the google play admob, you should use:

xmlns:ads="http://schemas.android.com/apk/res-auto"

that is why the ads: attributes were not recognized.

More infos see the official admob migration guide.

donfuxx
  • 11,277
  • 6
  • 44
  • 76
  • Did you notice that you had added legacy xmlns attribute inside the adView element? Your initial adView xml didn't had that, so I assume you had that attribute added elsewhere before? – donfuxx Sep 09 '14 at 16:33