1page.title=Setup 2@jd:body 3 4 5<p> 6 The Google Play services SDK is an extension to the Android SDK and is available to you as a 7 downloadable package from the <a href="{@docRoot}tools/help/sdk-manager.html">SDK 8 Manager</a>. The download includes the client library and code samples. 9</p> 10 11<p> 12 To develop using the <a href="{@docRoot}reference/gms-packages.html">Google 13 Play services APIs</a>, you must download the Google Play services SDK. 14 Additionally, you must provide a physical <strong>development device</strong> on 15 which you can run and debug your app. You can develop on any compatible Android 16 device that runs Android 2.2 or higher and includes the Google Play Store. 17 Ideally, you would develop and test the app on a variety of devices, including 18 both phones and tablets. 19</p> 20 21<p class="note"><strong>Note</strong>: Google Play services is not supported on the 22Android emulator — to develop using the APIs, you need to provide a development 23device such as an Android phone or tablet.</p> 24 25<p>To install the Google Play services SDK for development:</p> 26 27<ol> 28 <li>Launch the SDK Manager. 29 <ul> 30 <li>From Eclipse (with <a href="{@docRoot}tools/help/adt.html">ADT</a>), 31 select <strong>Window</strong> > <strong>Android SDK Manager</strong>.</li> 32 <li>On Windows, double-click the <code>SDK Manager.exe</code> file at the root of the Android 33 SDK directory.</li> 34 <li>On Mac or Linux, open a terminal and navigate to the <code>tools/</code> directory in the 35 Android SDK, then execute <code>android sdk</code>.</li> 36 </ul> 37 </li> 38 <li> 39 Scroll to the bottom of the package list, select <b>Extras > Google Play services</b>, 40 and install it. 41 <p>The Google Play services SDK is saved in your Android SDK environment at 42 <code><android-sdk-folder>/extras/google/google_play_services/</code>.</p> 43 </li> 44 <li>Copy the <code><android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib</code> 45 library project into the source tree where you maintain your Android app projects. 46 <p>If you are using Eclipse, import the library project into your workspace. Click <b>File > Import</b>, select <b>Android > Existing 47 Android Code into Workspace</b>, and browse to the copy of the library project to import it.</p> 48 </li> 49</ol> 50 51 52<p>To set up a project to use the Google Play services SDK:</p> 53 54<ol> 55 <li>Reference the library project in your Android project. 56 <p>See the 57 <a href="{@docRoot}tools/projects/projects-eclipse.html#ReferencingLibraryProject">Referencing a Library Project for Eclipse</a> 58 or <a href="{@docRoot}tools/projects/projects-cmdline.html#ReferencingLibraryProject">Referencing a Library Project on the Command Line</a> 59 for more information on how to do this.</p> 60 <p class="note"><strong>Note:</strong> 61 You should be referencing a copy of the library that you copied to your 62 source tree—you should not reference the library from the Android SDK directory.</p> 63 </li> 64 <li>If you are using <a href="{@docRoot}tools/help/proguard.html">ProGuard</a>, add the following 65 lines in the <code><project_directory>/proguard-project.txt</code> file 66 to prevent ProGuard from stripping away required classes: 67<pre> 68-keep class * extends java.util.ListResourceBundle { 69 protected Object[][] getContents(); 70} 71</pre> 72</ol> 73 74<h2 id="ensure">Ensuring Devices Have the Google Play services APK</h2> 75<p>As described in the <a href="{@docRoot}google/play-services/index.html">Google Play services 76introduction</a>, Google Play delivers service updates for users on 77Android 2.2 through the Google Play Store app. However, updates might not reach 78all users immediately.</p> 79 80<p class="caution"> 81<strong>Important:</strong> 82 Because it is hard to anticipate the state of each device, you must <em>always</em> check for a 83 compatible Google Play services APK in your app before you access Google Play services 84 features. For many apps, the best time to check is during the 85 {@link android.app.Activity#onResume onResume()} method of the main activity. 86</p> 87 88<p>Here are four scenarios that describe the possible state of the Google Play services APK on 89a user's device:</p> 90<ol> 91 <li> 92 A recent version of the Google Play Store app is installed, and the most recent Google Play 93 services APK has been downloaded. 94 </li> 95 <li> 96 A recent version of the Google Play Store app is installed, but the most recent Google Play 97 services APK has <em>not</em> been downloaded. 98 </li> 99 <li> 100 An old version of the Google Play Store app, which does not proactively download Google Play 101 services updates, is present. 102 </li> 103 <li> 104 The Google Play services APK is missing or disabled on the device, which might happen if the 105 user explicitly uninstalls or disables it. 106 </li> 107</ol> 108<p> 109 Case 1 is the success scenario and is the most common. However, because the other scenarios can 110 still happen, you must handle them every time your app connects to a Google Play service to 111 ensure that the Google Play services APK is present, up-to-date, and enabled. 112</p> 113<p> 114 To help you, the Google Play services client library has utility methods to 115 determine whether or not the Google Play services APK is recent enough to support the 116 version of the client library you are using. If not, the client library sends users to the 117 Google Play Store to download the recent version of the Google Play services APK. 118</p> 119 120<p class="note"> 121<b>Note:</b> 122<span> 123 The Google Play services APK is not visible by searching the Google Play Store. The client 124 library provides a deep link into the Google Play Store when it detects that the device has a 125 missing or incompatible Google Play services APK. 126</span> 127</p> 128 129<p> 130 It is up to you choose the appropriate place in your app to do the following steps to check for 131 a valid Google Play services APK. For example, if Google Play services is required for your app, 132 you might want to do it when your app first launches. On the other hand, if Google Play services 133 is an optional part of your app, you can do these checks if the user navigates to that portion 134 of your app: 135</p> 136 137<ol> 138 <li> 139 Query for the status of Google Play services on the device with the 140<a href="{@docRoot}reference/com/google/android/gms/common/GooglePlayServicesUtil.html#isGooglePlayServicesAvailable(android.content.Context)" 141>{@code isGooglePlayServicesAvailable()}</a> method, which returns a result code. 142 </li> 143 <li> 144 If the result code is 145<a href="{@docRoot}reference/com/google/android/gms/common/ConnectionResult.html#SUCCESS" 146>{@code SUCCESS}</a>, 147 then the Google Play services APK is up-to-date, and you can proceed as normal. 148 </li> 149 <li> 150 If the result code is 151<a href="{@docRoot}reference/com/google/android/gms/common/ConnectionResult.html#SERVICE_MISSING" 152>{@code SERVICE_MISSING}</a>, 153<a href="{@docRoot}reference/com/google/android/gms/common/ConnectionResult.html#SERVICE_VERSION_UPDATE_REQUIRED" 154>{@code SERVICE_VERSION_UPDATE_REQUIRED}</a>, 155 or 156<a href="{@docRoot}reference/com/google/android/gms/common/ConnectionResult.html#SERVICE_DISABLED" 157>{@code SERVICE_DISABLED}</a>, then 158 call <a href="{@docRoot}reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getErrorDialog(int, android.app.Activity, int)" 159 >{@code getErrorDialog()}</a> 160 to display an error message to the user, which allows the user to download the APK 161 from the Google Play Store or enable it in the device's system settings. 162 </li> 163</ol>