9

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.

Jason Aller
  • 3,391
  • 28
  • 37
  • 36
pikimota
  • 223
  • 1
  • 3
  • 14

2 Answers2

16

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.

Simas
  • 41,718
  • 10
  • 85
  • 115
  • Thanks, i'm using Eclipse, I imported google library using **File >> Import >> Existing Android code into workspace** then i added these library projects as dependencies to my project using **Project properties** . It is possible selectively compile Google Play Services library also in Eclipse? I'm a little bit confused... – pikimota Jan 12 '15 at 09:20
1

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?

Community
  • 1
  • 1
pikimota
  • 223
  • 1
  • 3
  • 14