3

I recently downloaded Android Studio, and now I am trying to build my project for which I was using Eclipse before. The project also utilizes GoogleMap API.

And in the code where I am using it and importing the library

import com.google.android.gms.location.LocationClient;

it shows me error:

Error:(40, 39) error: cannot find symbol class LocationClient

I have the code for google-play-services_lib which I had linked with the project as library in eclipse and it was working fine.

How can I do the same for Android Studio?

halfer
  • 19,824
  • 17
  • 99
  • 186
Maven
  • 14,587
  • 42
  • 113
  • 174

4 Answers4

8

Specifically for Google Play Services, first, install the "Google Repository", found in your SDK Manager.

Then, add a suitable dependency on com.google.android.gms:play-services to your dependencies closure:

apply plugin: 'com.android.application'

dependencies {
  compile 'com.google.android.gms:play-services:6.1.71'
}

android {
 // your project configuration goes here
}

There is a newer version, one that offers more modular dependencies, that you could explore, but I would start with 6.1.71 to get the basics working first before you optimize with the newer version.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I just check the line `compile 'com.google.android.gms:play-services:+'` already exists in Project > app > build.gradle > dependencies – Maven Dec 13 '14 at 16:04
  • 1
    @Maven: I would replace the `+` with something a bit more concrete (at least `6.1.+`). – CommonsWare Dec 13 '14 at 16:27
  • @CommonsWare: thanks for the link. How do you get all these information so fast? Is there a blog you can recommend? – Martin Pfeffer Dec 15 '14 at 19:41
  • 1
    @MartinPfeffer: http://android-developers.blogspot.com is where some of this stuff gets announced. – CommonsWare Dec 15 '14 at 20:07
6

Reverting to the old version of the Google Play Services Library, com.google.android.gms:play-services:6.1.71, will work but according to Google in version 6.5 of the library, LocationClient is Deprecated:

Deprecated clients - The ActivityRecognitionClient, LocationClient, and PlusClient classes are deprecated. If you used those APIs in your app and want to call Google Play services 6.5 or higher APIs, you must switch to the new programming model that utilizes GoogleApiClient. For more information about using GoogleApiClient, see Accessing Google APIs. Use these APIs instead of the deprecated APIs: If you were previously using ActivityRecognitionClient, call ActivityRecognition instead. If you were previously using LocationClient, call the APIs in the com.google.android.gms.location package instead. If you were previously using PlusClient, call the APIs in the com.google.android.gms.plus package instead.

Refer to this post if you'd like an example of using the new GoogleApiClient to retrieve location.

Source

Community
  • 1
  • 1
josacky
  • 136
  • 4
0

Android Studio uses gradle build system, you should use dependencies instead of library projects. Find build.gradle in your module directory and add this to the bottom

dependencies {
    compile 'com.google.android.gms:play-services:6.5.87'
}

Explaination here!

Community
  • 1
  • 1
Kirill Shalnov
  • 2,216
  • 1
  • 19
  • 21
  • I am getting `Could not find method compile() for arguments [com.google.android.gms:play-services:6.5.87] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated...` – Maven Dec 13 '14 at 15:54
  • @maven First. You have to add the dependencies to the AndroidStudioProjects/Project/Project/build.gradle, not AndroidStudioProjects/Project/build.gradle Second, you should to download Google Play Services from SDK Manager (dir Extra) – Kirill Shalnov Dec 13 '14 at 16:14
0

Right click on project name then select to "Open Module Settings". It will show a window with some tabs. Go to "Dependencies" tab see if "play-service (com.google.android.gms:play-services:x.x.xx)" is added or not. if not then click on '+' sign at the right top corner select the "module dependencies". you will see the list of dependencies choose the "play-service (com.google.android.gms:play-services:x.x.xx)" and click on ok. than on window apply and ok. and yes don't forgot to sync the gradle otherwise the changes might not work.

Hope this should solve your probelm.

Hardik Chauhan
  • 2,750
  • 15
  • 30