How to link a library project in Android Studio
I recently downloaded Android Studio
and now I am trying to build my project for which I used to use Eclipse before. The project also uses the GoogleMap API.
And in the code where I am using it and import the library
import com.google.android.gms.location.LocationClient;
it shows me the error:
Error:(40, 39) error: cannot find symbol class LocationClient
I have a code for google-play-services_lib
which I linked to a project as a library in eclipse and it worked fine.
But I don't know how to do the same for Android Studio
, please help.
source to share
Specifically for Google Play Services, first install the "Google Repository" which is in your SDK manager.
Then add a suitable dependency com.google.android.gms:play-services
to the closure dependencies
:
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 that offers more modular dependencies that you could look into, but I would start with 6.1.71 to get started with the base first, you are optimizing with the newer version.
source to share
Going back 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 the LocationClient library is deprecated:
Outdated clients. The ActivityRecognitionClient, LocationClient, and PlusClient classes have been deprecated. If you have used these APIs in your application and want to call Google Play Services 6.5 or higher APIs, you must switch to a new programming model that uses GoogleApiClient. For more information on using GoogleApiClient, see Accessing Google APIs. Use these APIs instead of the legacy APIs: If you've used ActivityRecognitionClient before, call ActivityRecognition instead. If you've used LocationClient before, call the API in the com.google.android.gms.location package. If you've used PlusClient before, call the API in the com.google.android.gms.plus package instead.
Refer to this post if you need an example of using the new GoogleApiClient to retrieve a location.
source to share
Right click on the project name and select Open Module Settings. It will display a window with some tabs. Click on the Dependencies tab to see if "play-service (com.google.android.gms: play-services: xxxx)" is added or not. if not, click "+" in the upper right corner, select "module dependencies". you will see a list of dependencies, select "play-service (com.google.android.gms: play-services: xxxx)" and click ok. than the window, and good. and yes, don't forget to sync gradle, otherwise the changes might not work.
Hope this should resolve your question.
source to share