简体   繁体   中英

Google Play Services - which min sdk to use

I have created an app but when I tried to test it on my minsdk which is API 21, google play services won't work.

The error I get is com.google.android.gms.common.api.ApiException: 4: .

I followed the setup guide , which means I have set my Google Play Services libs to version 11.8.0, it says I just have to use Android 4.2.2 which is API 17.

My compileSdkVersion is set to 27.

Is there something big I am misunderstanding here on how the compiling works? The app works fine on API 26 and 25, but fails when I try using it on API 24, with the same error as with API 21.

My build.gradle file looks like this. https://gist.github.com/uruloke/f2f71dd6318d365cd53d74c274cd8523

When using the GoogleSignInClient.silentSignIn() from the addOnFailureListener , I get the following exception

com.google.android.gms.common.api.ApiException: 4: 
                                                                at com.google.android.gms.common.internal.zzb.zzy(Unknown Source)
                                                                at com.google.android.gms.common.internal.zzbk.zzz(Unknown Source)
                                                                at com.google.android.gms.common.internal.zzbl.zzr(Unknown Source)
                                                                at com.google.android.gms.common.api.internal.BasePendingResult.zzc(Unknown Source)
                                                                at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
                                                                at com.google.android.gms.auth.api.signin.internal.zzg.zza(Unknown Source)
                                                                at com.google.android.gms.auth.api.signin.internal.zzt.onTransact(Unknown Source)
                                                                at android.os.Binder.execTransact(Binder.java:565)

Also if I try to use the GoogleSignInClient.getSignInIntent() , no intent is shown when starting it, but in my onActivityResult , I get an result which is non-successful, but with an empty status message

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        Log.d(TAG, result.getStatus().toString());
        if (result.isSuccess()) {
            // The signed in account is stored in the result.
            GoogleSignInAccount signedInAccount = result.getSignInAccount();
            menuFragment.updateUi(signedInAccount);
        } else {
            String message = result.getStatus().getStatusMessage();
            if (message == null || message.isEmpty()) {
                message = "Failed to sign in to Play Games. Maybe try updating it?";
            }
            new AlertDialog.Builder(this).setMessage(message)
                    .setNeutralButton(android.R.string.ok, null).show();
        }
    }
}

public static final int SIGN_IN_REQUIRED

The client attempted to connect to the service but the user is not signed in. The client may choose to continue without using the API. Alternately, if hasResolution() returns true the client may call startResolutionForResult(Activity, int) to prompt the user to sign in . After the sign in activity returns with RESULT_OK further attempts should succeed.

Constant Value: 4

Source: CommonStatusCodes , emphasis mine

It looks like silentSignIn only works if you're signed in to Google on the device, to be precise:

We attempt to sign users in if:

  • There is one and only one matching account on the device that has previously signed in to your application, and
  • the user previously granted all of the scopes your app is requesting for this sign in.

Source: GoogleSignInApi#silentSignIn

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