Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import com.google.android.gms.location.LocationServices, can't update location services

Tags:

android

I'm trying to test LocationService example as in http://developer.android.com/training/location/retrieve-current.html I fall in error which is really similar to

Can't Import com.google.android.gms.location.LocationServices

but I can't resolve.

I installed Google play services which version (in my Android SDK Manager ) is 17. I know that latest release is 19 but I'm not able to update version from SDK manager, I can't find any options for doing so.

in my code:

import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

first two are fine, third is getting:

import.... cannot be resolved

Edit 12/1/2015

I'm using Eclipse.

like image 439
pikimota Avatar asked Jan 09 '15 17:01

pikimota


2 Answers

You need to compile Google Play Services library into your project.

If you're using AndroidStudio:

Open up build.gradle and to you dependencies tag add this:

compile 'com.google.android.gms:play-services:6.+'

So it looks like:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.+'
}

With the new Play Services library you can selectively compile APIs (you might not need the whole library but just a part of it). You'd go for:

compile 'com.google.android.gms:play-services-location:6.+'

More about selective compilation here.

like image 164
Simas Avatar answered Nov 13 '22 05:11

Simas


I solved my problem but I don't know exactly how...

First I run Help >> Check for Updates

After doing so I updated Android SDK Tools and Android SDK Platform Tools from SDK Manager, then version of Google Play Services became 22 (before was 17).

My projects had then a red exclamation next to them... and an error saying

Google-play-services_lib Unable to resolve target 'android-9

I deleted google-play-services_lib from my Package Explorer, then re-add library using Import >> Existing Android Code Into Workspace

I don't know exactly wich operation solved the problem... i made so many attempts...

IMPORTANT

After updating SDK i came in an error saying

This Android SDK requires ADT version 23.0.0 or above.

so basically I uninstalled ADT (which version was 22.x) including:

  • Android Traceview
  • Android Hierarchy Viewer
  • Android Development Tools
  • Android DDMS
  • Tracer for OpenGL ES

    and install version 23 doing this

    1. Select Help > Install New Software 2.Work with: p2repo - https://dl-ssl.google.com/android/eclipse/
    2. Select Developer Tools and Next
    3. Next, Accept the license agreement* and Finish

as mentioned here [[This Android SDK requires ADT version 23.0.0 or above. Current version is 22.6. Please update ADT to the latest version?

like image 31
pikimota Avatar answered Nov 13 '22 05:11

pikimota