Failed to authenticate via GoogleAuthUtil.getToken ()
The application must authenticate the user on first launch (or in future launches if the first attempt fails). The authentication logic is encapsulated in AsyncTask
and implemented in the following method (user account and scope are valid):
private String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mParentActivity, mUserEmail, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
if (!secondTry) {
secondTry = true;
mParentActivity.handleException(userRecoverableException);
}
} catch (GoogleAuthException fatalException) {
fatalException.printStackTrace();
mParentActivity.handleException(fatalException);
}
return null;
}
handleException
:
public void handleException(final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode, MainActivity.this,
REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
Intent intent = ((UserRecoverableAuthException) e).getIntent();
startActivityForResult(intent, REQUEST_CODE_RECOVER_FROM_AUTH_ERROR);
} else if (e instanceof GoogleAuthException) {
showToast("Fatal error during authentication");
}
}
});
}
Testing this code on different devices has shown that there is no strict scheme for determining the cause of the error. Symptoms:
- multiple signature actions are displayed on top of each other, and none of them are performed:
- a few
UserRecoverableAuthException
are thrown even if I set the flagsecondTry
to prevent it;
Additionally, the following exceptions are noted in the LogCat:
11-10 13:50:30.610: D/GLSActivity(4223): Starting LoginActivityTask for user: qwerty@gmail.com...
11-10 13:50:30.615: E/Parcel(2345): Class not found when unmarshalling: com.google.android.gms.auth.firstparty.shared.LatencyTracker
11-10 13:50:30.615: E/Parcel(2345): java.lang.ClassNotFoundException: com.google.android.gms.auth.firstparty.shared.LatencyTracker
11-10 13:50:30.615: E/Parcel(2345): at java.lang.Class.classForName(Native Method)
11-10 13:50:30.615: E/Parcel(2345): at java.lang.Class.forName(Class.java:204)
11-10 13:50:30.615: E/Parcel(2345): at java.lang.Class.forName(Class.java:169)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Parcel.readParcelable(Parcel.java:2055)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Parcel.readValue(Parcel.java:1971)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Parcel.readMapInternal(Parcel.java:2255)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Bundle.unparcel(Bundle.java:223)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Bundle.getString(Bundle.java:1082)
11-10 13:50:30.615: E/Parcel(2345): at android.content.Intent.getStringExtra(Intent.java:4961)
11-10 13:50:30.615: E/Parcel(2345): at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
11-10 13:50:30.615: E/Parcel(2345): at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977)
11-10 13:50:30.615: E/Parcel(2345): at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3173)
11-10 13:50:30.615: E/Parcel(2345): at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3129)
11-10 13:50:30.615: E/Parcel(2345): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:157)
11-10 13:50:30.615: E/Parcel(2345): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125)
11-10 13:50:30.615: E/Parcel(2345): at android.os.Binder.execTransact(Binder.java:388)
11-10 13:50:30.615: E/Parcel(2345): at dalvik.system.NativeStart.run(Native Method)
11-10 13:50:30.615: E/Parcel(2345): Caused by: java.lang.NoClassDefFoundError: com/google/android/gms/auth/firstparty/shared/LatencyTracker
11-10 13:50:30.615: E/Parcel(2345): ... 18 more
11-10 13:50:30.615: E/Parcel(2345): Caused by: java.lang.ClassNotFoundException: Didnt find class "com.google.android.gms.auth.firstparty.shared.LatencyTracker" on path: .
11-10 13:50:30.615: E/Parcel(2345): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
11-10 13:50:30.615: E/Parcel(2345): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-10 13:50:30.615: E/Parcel(2345): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-10 13:50:30.615: E/Parcel(2345): ... 18 more
...
11-10 13:50:30.625: E/Parcel(2345): Class not found when unmarshalling: com.google.android.gms.auth.firstparty.shared.AppDescription
11-10 13:50:30.625: E/Parcel(2345): java.lang.ClassNotFoundException: com.google.android.gms.auth.firstparty.shared.AppDescription
11-10 13:50:30.625: E/Parcel(2345): at java.lang.Class.classForName(Native Method)
11-10 13:50:30.625: E/Parcel(2345): at java.lang.Class.forName(Class.java:204)
11-10 13:50:30.625: E/Parcel(2345): at java.lang.Class.forName(Class.java:169)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Parcel.readParcelable(Parcel.java:2055)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Parcel.readValue(Parcel.java:1971)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Parcel.readMapInternal(Parcel.java:2255)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Bundle.unparcel(Bundle.java:223)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Bundle.getString(Bundle.java:1082)
11-10 13:50:30.625: E/Parcel(2345): at android.content.Intent.getStringExtra(Intent.java:4961)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3391)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:254)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3283)
11-10 13:50:30.625: E/Parcel(2345): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:258)
11-10 13:50:30.625: E/Parcel(2345): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125)
11-10 13:50:30.625: E/Parcel(2345): at android.os.Binder.execTransact(Binder.java:388)
11-10 13:50:30.625: E/Parcel(2345): at dalvik.system.NativeStart.run(Native Method)
11-10 13:50:30.625: E/Parcel(2345): Caused by: java.lang.NoClassDefFoundError: com/google/android/gms/auth/firstparty/shared/AppDescription
11-10 13:50:30.625: E/Parcel(2345): ... 19 more
11-10 13:50:30.625: E/Parcel(2345): Caused by: java.lang.ClassNotFoundException: Didnt find class "com.google.android.gms.auth.firstparty.shared.AppDescription" on path: .
11-10 13:50:30.625: E/Parcel(2345): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
11-10 13:50:30.625: E/Parcel(2345): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-10 13:50:30.625: E/Parcel(2345): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-10 13:50:30.625: E/Parcel(2345): ... 19 more
Does anyone have any suggestions what is causing this problem?
+3
source to share
No one has answered this question yet
Check out similar questions: