简体   繁体   中英

Cannot connect to GoogleApiClient due to errorcode: SERVICE_VERSION_UPDATE_REQUIRED

I am developing on Andriod Studio, and I created an instance of GoogleApiClient like such:

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

I have a onConnectionFailed handler like this:

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(ACTRequest.this, 6);
        } catch (IntentSender.SendIntentException e) {
        }
    } else {
        //Connection failure cannot be resolved
        Toast.makeText(getApplicationContext(),
                "Unable to connect to Google Service, sorry >_<" + connectionResult.getErrorMessage(), Toast.LENGTH_LONG)
                .show();
        Log.d("CONNECTION FAIL", connectionResult.getErrorCode() + " Unable to connect to Google Service, sorry >_<");
    }
}

Everytime this activity runs, I get error code: 2 = SERVICE_VERSION_UPDATE_REQUIRED

To resolve this, I installed the Google Play Service revision 29.0.0 on android studio, and I made sure that my emulator has API23. however, I am still getting this error.

I am not sure what to do at this point, how could I update the google play services on my emulator? Is there something wrong with my code?

Work Around:

Thanks for suggesting the 2.0 emulator! Here is another way I found to resolve (sort of) this issue:

Since it is very difficult to update the google play service on the emulator, we can intead lower the version in the gradle dependencies for google-services to 1.5.0-beta1 when we build the project:

dependencies {
    classpath 'com.android.tools.build:gradle:1.3.1'
    classpath 'com.google.gms:google-services:1.5.0-beta1'
}

And use:

compile 'com.google.android.gms:play-services:8.1.0' 

This is not recommended however.

要使用模拟器,请使用当前预览版中的新模拟器2.0版: http : //tools.android.com/tech-docs/emulator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM