Thursday, August 14, 2014

Migrating from Android SDK to Google Play Services SDK

If you are using android sdk for developing android applications then its time to migrate to Google Play Services sdk.

You might have noticed the below notification on new admob website.

On Aug. 1 2014, Google Play will stop accepting new or updated apps using the standalone Google Mobile Ads SDKs v6.4.1 or lower. Upgrade to the Google Play version of the Mobile Ads SDK to take advantage of new features, including automatic updates such as bug fixes.

If you are currently using android sdk then follow below steps to migrate to Google Play Services sdk.

1) Update some tools in existing Android SDK Manager.

Open Android SDK manager and install/update following tools as shown in below screenshot.

Android Support Repository
Android Support Library
Google Repository
Google Play services


2) Import Google Play Service Library Project into your workspace.

Library project is located in sdk directory : <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/

Import this library project into your Eclipse workspace. 

Click File > Import, select Android > Existing Android Code into Workspace, Select above directory as root directory.
library project will appear in project list. Select google-play-services_lib project and click on Finish.
Make sure to select ‘Copy projects into workspace’



3) Reference google play services library project into your android application project.

Right click on your android app project, goto Properties, select Android. 
In the Library section, click on Add , select google-play-services_lib project and click ok.



4) Modify your android application’s manifest file.

Open your app's manifest file and add the following tag as a child of the <application> element:

<meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

Thats it. Now you can use Google Play Services API into your android project.

Notes:

1) To prevent ProGuard from stripping away required classes, add the following lines in the <project_directory>/proguard-project.txt file:

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

2) You have to remove admob sdk jar file if you have in libs directory.

3) If you are using Google Play Services SDK for android application development, then your app will depend on google play store and google play services apk on client devices.

So before using the google play services features from your app, you should check whether client’s android device has compatible google play services apk or not?
You can perform this check on your activity’s onResume method.

Google play services library that you have just integrated, includes utility methods to check the compatibility of google play services on user’s android devices.

To verify the Google Play services version, call isGooglePlayServicesAvailable(). If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update. So, call GooglePlayServicesUtil.getErrorDialog() and pass it the result error code. This returns a Dialog you should show, which provides an appropriate message about the error and provides an action that takes the user to Google Play Store to install the update.

Migrate your code into new google play services SDK as per this google checklist 

Common problems you may encounter during this migration activity


1) In eclipse, google-play-service_lib project has error : unable to get system library for the project

If you got this error, then following these steps to fix it.

Right click on google-play-service_lib project
Go to properties
Click the Android section and select project build target as below.



2) Android Lint error while exporting app to apk : <key> is not translated in <language> error.

In "Window" > "Preferences" > "Android" > "Lint Error Checking"

Find the MissingTranslation line, and set it to Warning as seen below:




2 comments:

Creating and Deploying Java Web Application on AWS using Elastic Beanstalk

This tutorial is for creating simple java web application using eclipse and then deploying it on AWS cloud. Video tutorial for creating/de...