Upgrade old admob to Google Play Service






Credit This is a tutorial from : http://tutorialrich.com/extra-upgrade-old-admob-to-google-play-service/

 

I always follow this step to upgrade legacy android apps.

 

You should update to the latest Google Play service and it is better choice compare to standalone admob SDK. We are going to teach you how to update your old android code to the latest Google Play services.

 

Step 1:

Open your old Admob Project. Delete the GoogleAdMobAdsSDK.jar inside the libs folder. (Next : Just ignore the reference warning.)

 

admobsdkdelete

 

Step 2:

Setup Google Play service.

 

 

Android SDK

1. Launch the SDK Manager in one of the following ways:

  • In Android Studio, click SDK Manager in the toolbar.

  • In Eclipse (with ADT), select Window > Android SDK Manager


2. Install the Google Play services SDK. Google Play Services

Scroll to the bottom of the package list, expand Extras, select Google Play services, and install it. The Google Play services SDK is saved in your Android SDK environment at /extras/google/google_play_services/. Note: Google Play services 4.0.30 (released November 2013) and newer versions require Android 2.3 or higher. If your app supports Android 2.2, you can continue development with the Google Play services SDK, but must instead install Google Play services for Froyo from the SDK Manager. 4. Make a copy of the Google Play services library project. If you are using Eclipse, import the library project into your workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
Screen Shot 2014-06-24 at 12.01.11 AMNote if you testing Google Play Services SDK.Google Mobile Ads SDK FAQ states that: If you keep getting the error ‘The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. the google play services resources were not foundYou can safely ignore this message. Your app will still fetch and serve banner ads.

 

After setup the Google Play Service.Right click on project properties and add the google-play-service in the Library section.

android play library

 

Step 3:

Remove the import import com.google.ads.* code .

NewImage

and add the following code import com.google.android.gms.ads.*;

NewImage

 

Step 4:

Open the AndroidManifest.xml and remove the <activity android:name=”com.google.ads.AdActivity”

NewImage

 

add the following code :
<activity android:name="com.google.android.gms.ads.AdActivity"…/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

NewImage

Step 5:

Remove the following code

AdView adView =newAdView(activity,AdSize.BANNER,
   
"MY_AD_UNIT_ID");


NewImage

and add the following code.

 

AdView adView = (AdView)this.findViewById(R.id.adView);


    AdRequest adRequest = new AdRequest.Builder()


       .build();


    adView.loadAd(adRequest);




NewImage

Step 6:

Remove the following code
AdRequest request =newAdRequest()
   
.addTestDevice(AdRequest.TEST_EMULATOR);

NewImage

 

and add the following code
AdRequest request =newAdRequest.Builder()
   
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
   
.build();

 

 

Step 7:

If the you use the ads view inside the XML files instead of java code. Remove the following code.

 

<com.google.ads.AdViewandroid:id=“@+id/adView”

 

android:layout_width=“wrap_content”

 

android:layout_height=“wrap_content”

 

android:layout_gravity=“center”

 

ads:adUnitId=“yourid”

 

ads:adSize=“BANNER”

 

ads:loadAdOnCreate=“true”/>

 

NewImage

 

and add to the following code in xml layout and src code.

 
<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="MY_AD_UNIT_ID"
   
ads:adSize="BANNER"/>

// Java code required.
// testDevices and loadAdOnCreate attributes are
// no longer available.


AdView adView = (AdView)this.findViewById(R.id.adView);

 

AdRequest adRequest = new AdRequest.Builder()

 

.build();

adView.loadAd(adRequest);

NewImage

 

 
and modify the code in the xml.


Step 8:

Since you remove the GoogleAdmobJar, you must also remove the setting in order to compile the code.

NewImage

 

On the project properties, go to Java Builder Path and remove the missing jar.

NewImage

Next, clean the project and run the NewImage program.

Upgrade old admob to Google Play Service Upgrade old admob to Google Play Service Reviewed by Admin on 4:12 PM Rating: 5

No comments:

Powered by Blogger.