Google sign in failed after frequent signing in and out
<p>I can sign in my app with Google account at first several times.
Everything is fine.</p>

<p>But if I sign in and out about 20 times in a one or two minutes.
Google sign in failed and in <code>onActivityResult</code> function, it returns error code 12501, resultCode = 0;</p>

<p>I'm using the phone: Nexus 6, Android 5.1.1</p>

<p>Here is my code：</p>

<pre><code>private GoogleSignInOptions mGso;
private GoogleApiClient mGac;

public void init(@NonNull final BaseActivity activity) {
    mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(activity.getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGac = new GoogleApiClient.Builder(activity)
            .enableAutoManage(activity /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    ToastUtils.show(activity, R.string.login_failed);
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API, mGso)
            .build();
}

public void signIn(@NonNull final BaseActivity activity,
                   @NonNull GoogleSignInCallback callback,
                   @NonNull final OnLoadingListener&lt;PlatformUserEntity&gt; listener) {

    callback.registerCallback(listener);
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGac);
    activity.startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGNIN);

    // disconnect the client
    mGac.stopAutoManage(activity);
    mGac.disconnect();

}
</code></pre>

<p>Here is gradle:</p>

<pre><code>compile 'com.google.android.gms:play-services-base:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.google.android.gms:play-services-auth:9.6.1'
</code></pre>

<p>Fisrt, I init the GoogleApiClient with a FragmentActivity, then signIn function starts the Acitvity. GoogleSignInCallback is registered in the onActivityResult function. Then disconnect the Client because every time the sign in button is clicked, the init function will be invoked.</p>

<p>I doubt that I use <code>stopAutoManage()</code> too early but it seems like not true.
So I'm confused, which part might be wrong?</p>

<p>I noticed the log:</p>

<pre><code>Could not set socket write timeout: null
12-03 17:21:43.859 264-264/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
12-03 17:21:43.902 1946-12870/? W/Conscrypt: Could not set socket write timeout: null
12-03 17:21:44.327 21168-21168/? W/AccountChipsFragment: Recording consent failed.
12-03 17:21:44.657 29359-29782/? E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
12-03 17:21:44.664 812-1072/? W/ActivityManager: getRunningAppProcesses: caller 10145 does not hold REAL_GET_TASKS; limiting output
12-03 17:21:44.697 21168-21168/? W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.
</code></pre>

<p>It said "You have wrong OAuth2 related configuration", but I could use the web client id to request the IdToken at the first time.</p>

<p>It just makes me more confused.</p>

<p>I also found a strange thing. If I install the apk which is built locally, this error never happened. If I download from google play store, this error ocurred. But there is no difference between these two apks because I deliver google store with the local one. </p>