Dmac
Dmac

Reputation: 904

Cannot Resolve Symbol Google API Client in Android Studio

I'm getting an error in Android Studio for the following:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API).build();

I have put this in my manifest, <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

and compile 'com.google.android.gms:play-services:6.5.87' in my gradle dependencies.

I've downloaded the required sdk files as well.

Why do I still get this error?

Upvotes: 23

Views: 58446

Answers (7)

Gilad Levinson
Gilad Levinson

Reputation: 234

the question is old ,but now that GoogleApiClient is deprecated I found out that I can't use it anymore and that one should use its substitute, subclasses of GoogleApi .

Upvotes: 0

Shahan Mehbub
Shahan Mehbub

Reputation: 77

Add following lines to your dependencies to use Google Places Api interfaces

dependecies{compile 'com.google.android.gms:play-services:11.2.0'
testCompile 'junit:junit:4.12'

}

Upvotes: 1

Tayebeh Hosseini
Tayebeh Hosseini

Reputation: 11

I had this problem, only with import com.google.android.gms.common.api.GoogleApiClient;I unfortunately had moved <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> after its relative activity <activity android:name=".MapsActivity" android:label="@string/title_activity_maps" ></activity>. I returned to previous state and the problem was solved.

Upvotes: 1

Gaurav
Gaurav

Reputation: 559

Just to log the problem.

This happens when there is version conflict. Check the build message, and it will suggest the version you should be importing.

The classpath version in main gradle (classpath 'com.google.gms:google-services:3.1.0') should be complaint with the version of jar included in the app gradle (compile 'com.google.android.gms:play-services-auth:11.0.0')

Upvotes: 0

bmul
bmul

Reputation: 390

I had to do the following to get my app to compile successfully:

  1. Update my build.grade with 'com.google.android.gms:play-services:<version>'
  2. Add imports as needed:

    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.api.ResultCallback;
    import com.google.android.gms.common.api.Status;
    
  3. In Android Studio: File --> Invalidate/Restart...

  4. Clean build

Upvotes: 6

JJJCoder
JJJCoder

Reputation: 16946

For the benefit of searchers:

If you are following the android tutorial that relates to this, you can add the dependency via the UI.

  1. In Android Studio, go to File > Project Structure.
  2. Go to the dependencies tab.
  3. On the right hand side add a 'Library Dependency'.
  4. Type "com.google.android.gms:play-services" into the searchbox and pick the appropriate dependency.
  5. Then follow @Dmac's answer

Upvotes: 41

Dmac
Dmac

Reputation: 904

Even though not officially listed in the tutorial, you must use the following imports:

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

Upvotes: 16

Related Questions