17

I'm trying to test LocationService example of Android developer as per following link http://developer.android.com/training/location/retrieve-current.html. At that time, error message show me that "The import com.google cannot be resolved" for following 5 lines. I'm really confused how to solve this problem.

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
PPShein
  • 13,309
  • 42
  • 142
  • 227

14 Answers14

19

You will need the Google Play Services SDK configured within Eclipse and import google play services as library will dismiss this error .

Manmohan Badaya
  • 2,326
  • 1
  • 22
  • 35
  • 15
    How do I import Google Play Services as library in an appropriate way? – Kann May 05 '14 at 10:44
  • 4
    Menu window -> Android SDK Manager. Find "Google Play Services" under "extras". If it's not installed, check it and install it. Then, in your Eclipse project, go to your Java Build Path, add external jar, then locate the google-play-services.jar, it's somewhere in your android sdk (in my case it's `android-sdk-linux/extras/google/google_play_services/libproject/google-play-services_lib/libs` – Jos de Jong Jun 17 '15 at 09:06
18

There is a much simpler solution. In my case, I've gone through all the answers from a few sources and none of them give a straight answer to my problem. Finally, I found a sample app source code and when I import the source code I found out adding the library from Google Play Service Library directory solved it. Google Play Service Library is located (for windows user) here:

    \sdk\extras\google\google_play_services\libproject

Import the library into Eclipse as a library project and add this library in your actual project will fix it.

EDIT: This guy made a great contribution on his tutorials how to use Android Google Map v2 step by step and very details. It also includes how to use with Android Support package’s backport of fragments.

    http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part1
Sithu
  • 4,241
  • 1
  • 20
  • 28
10

Assuming you use Eclipse.
Right-click on your project -> properties -> Android.
There use Google API's instead of standard Android.

Bigflow
  • 3,616
  • 5
  • 29
  • 52
8

If you're using Android Studio:

Right click on your app folder -> Open Module Settings -> Dependencies -> Click on the plus button -> Choose library dependency -> Search for "play-services" -> Double click on the com.google.android.gms:play-services

Press Ok and wait for Gradle to rebuild.

moritzwick
  • 613
  • 1
  • 10
  • 16
5

You can use this way. First of all close projects which are using google-play-services library. Whenever your mouse over the com.google.android.gms import that can not be resolved and towards the bottom of the popup menu, select the "Fix project setup" option as below. Then it'll prompt to import the google-play-services library.

enter image description here

Parthi
  • 669
  • 1
  • 9
  • 26
4

If you're using Eclipse, you can fix this by installing Google Play Services SDK via the SDK Manager, load the google-play-services-lib project into Eclipse, and set this as a reference from your project. This is documented at http://developer.android.com/google/play-services/setup.html

Anthony
  • 71
  • 1
  • Just wanted to emphasize you load it as a project, and not a library or anything like that. And thanks a lot because it's no longer documented there; Google changed the page. – Noumenon Dec 17 '14 at 10:19
2

Do you use android sdk with google api? If not, do that and it will work.

Cata
  • 11,133
  • 11
  • 65
  • 86
0

set your project properties to google api.

URAndroid
  • 6,177
  • 6
  • 30
  • 40
0

You will need the Google Play Services SDK configured within Eclipse.

0

Maybe useful for some other developers facing this error: If you are changing to a newer Android Version and if you are using the android-support-library, you have to beware that all projects that you use as library also have the SAME version of the android-support-library. One example would be the actionbar-sherlock. ;)

Sorcerer
  • 854
  • 1
  • 8
  • 20
0

It Works = Do you use android sdk with google api? If not, do that and it will work.

Sachin
  • 69
  • 3
0

In project.properties I had to add the following (for ANT build):

android.library.reference.1=${root_prefix}/${sdk.dir}/extras/google/google_play_services/libproject/google-play-services_lib
apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69
0

If you are using Android studio you may be missing to add gradle to your project.

Add specific play service you want. Here you may want to compile

com.google.android.gms:play-services-location:10.2.1

Add this to your build.gradle app module in dependencies.

Shaishav Jogani
  • 2,111
  • 3
  • 23
  • 33
Nisargi Joshi
  • 286
  • 3
  • 12
0

In android studio,add dependency as follows:

In gradle script,go in build.gradle(Module:app) and add these lines

compile 'com.google.android.gms:play-services:10.0.1' in dependencies tag

Here 10.0.1 may be skipped or changed according to your library installed

AnkurSingh
  • 11
  • 3
  • This is not recommended as this may lead to [65K methods limit](https://developers.google.com/android/guides/setup) error. So, use specific library dependency from `gms:play-services`. – Shashanth Jun 26 '17 at 05:37