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.)

Step 2:
Setup Google Play service.

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.

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.


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

Step 3:
Remove the import import com.google.ads.* code .

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

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

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"/>

Step 5:
Remove the following code
AdView adView =newAdView(activity,AdSize.BANNER,
"MY_AD_UNIT_ID");

and add the following code.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);

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

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”/>

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);

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.

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

Next, clean the project and run the

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