使用Google登录时SignInConfiguration的ClassNotFoundException

时间:2016-03-30 12:40:25

标签: android google-play-services

我正在实施Google登录应用。登录本身似乎工作正常,但是当我请求用户的电子邮件或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

这是我用来尝试登录用户的代码:

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'

记录的异常似乎来自另一个进程。我甚至试图将我的活动设为com.google.android.gms.auth.api.signin.internal.SignInConfiguration,以确保我可以访问该课程。

这发生在不使用proguard的调试版本中。

4 个答案:

答案 0 :(得分:8)

我认为这可能是一个红鲱鱼。我有完全相同的堆栈跟踪,并花了很多时间来确定原因。我在研究时发现了一个类似的帖子,表明它可能是三星唯一可以忽略的例外(他们检查运输中的意图或其他东西)。果然,我尝试了HTCOne设备,不再出现例外情况。我仍然有相同的整体Google Auth问题,但至少我可以转到真正的问题(至少对我来说)似乎是SHA /证书/帐户/签名相关。无论如何 - 希望这有帮助(无论如何要检查)

答案 1 :(得分:2)

我通过将"App signing Key"添加到OAuth 2.0客户端ID SHA-1指纹而不是使用keytool生成的签名密钥来解决了我的问题。如果您已选中" Google Play App Signing"在Google Play控制台中,通常的签名密钥不起作用。在Google Play台上查看您的应用签名密钥>应用签名>应用签名证书,然后复制SHA-1证书指纹并粘贴到Google API控制台OAuth 2.0客户端ID。它对我有用!

答案 2 :(得分:0)

我已通过以下方式解决了此问题:我在google开发人员控制台中删除了我的项目,并创建了另一个具有不同名称的项目,而且我几乎完全更改了包名:例如,从com .example.android.appname改为com.y.android.anothername。然后,我使用以前的证书生成了签名的apk,并且Google签名在没有给我该错误的情况下起作用。

答案 3 :(得分:0)

我遇到了同样的问题,我发现我在 Google 登录期间在 requestIdToken() 中使用了错误的 default_web_client_id。

解决方案:

  1. 打开https://console.cloud.google.com/apis/credentials
  2. OAuth 2.0 客户端 ID
  3. 复制Web 客户端(由 Google 服务自动创建)
  4. 将此密钥粘贴到您的 GoogleSignInOptions.Builder 的 requestIdToken() 中