Google Play 服务 - 使用哪个 min sdk

Google Play Services - which min sdk to use

我已经创建了一个应用程序,但是当我尝试在我的 API 21 的 minsdk 上测试它时,google 播放服务将无法运行。

我得到的错误是 com.google.android.gms.common.api.ApiException: 4:

我遵循了 setup guide,这意味着我已经将我的 Google Play Services 库设置为版本 11.8.0,它说我只需要使用 Android 4.2.2是 API 17.

我的compileSdkVersion设置为27。

我对编译的工作方式有什么误解吗?该应用程序在 API 26 和 25 上运行良好,但当我尝试在 API 24 上使用它时失败,出现与 API 21.

相同的错误

我的 build.gradle 文件如下所示。 https://gist.github.com/uruloke/f2f71dd6318d365cd53d74c274cd8523

当使用 addOnFailureListener 中的 GoogleSignInClient.silentSignIn() 时,出现以下异常

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)

此外,如果我尝试使用 GoogleSignInClient.getSignInIntent(),启动时不会显示意图,但在我的 onActivityResult 中,我得到的结果是不成功的,但状态为空留言

@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

来源:CommonStatusCodes,强调我的

看起来 silentSignIn 只有在您在设备上登录 Google 时才有效,准确地说:

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.

来源:GoogleSignInApi#silentSignIn