Reputation:
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?
Upvotes: 3
Views: 3272
Reputation: 146
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.
Upvotes: 6
Reputation: 2746
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.
Upvotes: 0
Reputation: 2216
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!
Upvotes: 0
Reputation: 1007658
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.
Upvotes: 8