使用Googlelogin时,SignInConfiguration的ClassNotFoundException

我正在实施Googlelogin到应用程序。 login本身似乎工作正常,但是一旦我请求用户的电子邮件或ID令牌,我看到在日志中的以下堆栈跟踪和状态从GoogleSignInResult作为Status{statusCode=unknown status code: 12500, resolution=null}

 03-30 13:59:09.821 3634-4322/? E/Parcel: Class not found when unmarshalling: com.google.android.gms.auth.api.signin.internal.SignInConfiguration java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInConfiguration at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:309) at java.lang.Class.forName(Class.java:273) at android.os.Parcel.readParcelableCreator(Parcel.java:2281) at android.os.Parcel.readParcelable(Parcel.java:2245) at android.os.Parcel.readValue(Parcel.java:2152) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.getString(BaseBundle.java:918) at android.content.Intent.getStringExtra(Intent.java:5767) at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:2365) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1848) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:5809) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:5593) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:142) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3786) at android.os.Binder.execTransact(Binder.java:461) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.internal.SignInConfiguration" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:309) at java.lang.Class.forName(Class.java:273) at android.os.Parcel.readParcelableCreator(Parcel.java:2281) at android.os.Parcel.readParcelable(Parcel.java:2245) at android.os.Parcel.readValue(Parcel.java:2152) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.getString(BaseBundle.java:918) at android.content.Intent.getStringExtra(Intent.java:5767) at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:2365) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1848) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:5809) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:5593) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:142) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3786) at android.os.Binder.execTransact(Binder.java:461) Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInConfiguration at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 18 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

这是我用来login用户的代码:

 public class SignInActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener { private final static String TAG = SignInActivity.class.getSimpleName(); protected final static int REQUEST_CODE_GOOGLE_LOGIN = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) // .requestEmail() // Causes ClassNotFoundException for SignInConfiguration // .requestIdToken(getString(R.string.google_server_client_id)) // Causes ClassNotFoundException for SignInConfiguration .build(); final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) .build(); SignInButton signInButton = (SignInButton) findViewById(R.id.signInButton); signInButton.setScopes(googleSignInOptions.getScopeArray()); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); startActivityForResult(signInIntent, REQUEST_CODE_GOOGLE_LOGIN); } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_GOOGLE_LOGIN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); handleGoogleSignInResult(result); } } protected void handleGoogleSignInResult(GoogleSignInResult googleSignInResult) { Logging.debug(TAG, "handleGoogleSignInResult(" + googleSignInResult + ")"); if (googleSignInResult.isSuccess()) { GoogleSignInAccount googleSignInAccount = googleSignInResult.getSignInAccount(); final String idToken = googleSignInAccount.getIdToken(); if (idToken != null) { Toast.makeText(SignInActivity.this, "Successfully logged in.", Toast.LENGTH_SHORT).show(); // Do fun stuff here } else { Log.e(TAG, "ID token was null. Unable to sign in user."); } } else { Log.e(TAG, "Failed to sign in with Google. Status:" + googleSignInResult.getStatus()); } } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "onConnectionFailed(" + connectionResult + ")"); } } 

我究竟做错了什么?

我正在使用以下gradle依赖项:

 compile 'com.google.android.gms:play-services-auth:8.4.0' 

logging的exception似乎来自另一个进程。 我甚至试图instanciate com.google.android.gms.auth.api.signin.internal.SignInConfiguration我的活动,以确保我有类访问。

这是发生在不使用proguard的debugging版本上。

Solutions Collecting From Web of "使用Googlelogin时,SignInConfiguration的ClassNotFoundException"

我想这可能是一个红鲱鱼。 我有完全相同的堆栈跟踪,花了大量的时间来确定原因。 我在研究中发现了一个类似的post,指出这可能是三星唯一可以忽略的例外(他们在运输过程中检查意图)。 果然,我尝试了一个HTCOne设备,并不再出现exception。 我仍然有相同的整体Google Auth问题,但至less我可以转到真正的问题上(至less对我来说)似乎是SHA / Cert / Account / Signing相关的问题。 无论如何 – 希望这有助于(无论如何检查)

我通过将“应用程序签名密钥”放入OAuth 2.0客户端ID SHA-1指纹而不是使用keytool生成的签名密钥来解决了我的问题。 如果您在Google Play控制台中选中了“Google Play应用签名”,则通常签名的密钥将无法使用。 在Google Play控制台>应用签名>应用签名证书中签出您的应用签名密钥,然后复制SHA-1证书指纹并粘贴到Google API控制台OAuth 2.0客户端ID。 它为我工作!