Google登录无效

时间:2016-09-30 11:07:26

标签: android android-intent google-signin

我正在关注Google's documentation Google Sign。我打电话时有一个奇怪的问题

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent (mGoogleApiClient);
        startActivityForResult (signInIntent, RC_SIGN_IN);

似乎Intent已被解雇,但我看不到帐号选择器对话框。我正在使用

compile "com.google.android.gms:play-services-auth:9.6.1"

当我检查googleclient对象是否已连接时,它返回true。

  

它在某些设备上工作,但不是在每台设备上工作(特别是xiaomi)

实施

@OnClick (R.id.google_singin_button)
void signInButtonClicked () {

    HashMap<String, Object> map = new HashMap<> ();
    map.put (AllAnalytics.LABEL, AllAnalytics.Label.SIGN_IN_GOOGLE);
    map.put (AllAnalytics.ACTION, AllAnalytics.Action.CLICK);
    map.put (AllAnalytics.CATEGORY, AllAnalytics.Category.REGISTRATION_SCREEN);

    aa.analyticsEventOccur (map);

    if (null != mGoogleApiClient) {
       // Log.e(TAG,mGoogleApiClient.isConnected()+"");
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent (mGoogleApiClient);
        startActivityForResult (signInIntent, RC_SIGN_IN);
    }
}

@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
    super.onActivityResult (requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if(Activity.RESULT_CANCELED != resultCode)
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent (data);
        handleSignInResult (result);
    }
}

@Override
public void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    mActivity = (RegisterActivity) getActivity ();
    GoogleSignInOptions gso
            = new GoogleSignInOptions.Builder (GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestServerAuthCode (getString (R.string.google_client_auth), false)
            .requestEmail ()
            .build ();

    mGoogleApiClient = new GoogleApiClient.Builder (getContext ())
            .enableAutoManage (mActivity , this)
            .addApi (Auth.GOOGLE_SIGN_IN_API, gso)
            .build ();

}

Log Cat

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.containsKey(BaseBundle.java:269)
   at android.content.Intent.hasExtra(Intent.java:4884)
   at com.miui.server.XSpaceManagerService.isPublicIntent(XSpaceManagerService.java:174)
   at com.android.server.am.ActivityStackSupervisorInjector.checkXSpaceControl(ActivityStackSupervisorInjector.java:56)
   at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:897)
   at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478)
   at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465)
   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245)
   at android.os.Binder.execTransact(Binder.java:446)
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.containsKey(BaseBundle.java:269) 
   at android.content.Intent.hasExtra(Intent.java:4884) 
   at com.miui.server.XSpaceManagerService.isPublicIntent(XSpaceManagerService.java:174) 
   at com.android.server.am.ActivityStackSupervisorInjector.checkXSpaceControl(ActivityStackSupervisorInjector.java:56) 
   at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:897) 
   at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478) 
   at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465) 
   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) 
   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245) 
   at android.os.Binder.execTransact(Binder.java:446) 
    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)
        ... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

10-11 23:46:17.873 1387-4537/? E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
java.lang.RuntimeException: Parcel android.os.Parcel@33c1f490: Unmarshalling unknown type code 6684783 at offset 320
   at android.os.Parcel.readValue(Parcel.java:2228)
   at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
   at android.os.BaseBundle.unparcel(BaseBundle.java:221)
   at android.os.BaseBundle.containsKey(BaseBundle.java:269)
   at android.content.Intent.hasExtra(Intent.java:4884)
   at com.miui.server.XSpaceManagerService.shouldResolveAgain(XSpaceManagerService.java:145)
   at com.android.server.am.ActivityStackSupervisorInjector.resolveXSpaceIntent(ActivityStackSupervisorInjector.java:68)
   at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:898)
   at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478)
   at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465)
   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245)
   at android.os.Binder.execTransact(Binder.java:446)


10-11 23:46:17.873 1387-4537/? A/ActivityManager: Activity Manager Crash
java.lang.RuntimeException: Parcel android.os.Parcel@33c1f490: Unmarshalling unknown type code 6684783 at offset 320
    at android.os.Parcel.readValue(Parcel.java:2228)
    at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
    at android.os.BaseBundle.unparcel(BaseBundle.java:221)
    at android.os.BaseBundle.containsKey(BaseBundle.java:269)
    at android.content.Intent.hasExtra(Intent.java:4884)
    at com.miui.server.XSpaceManagerService.shouldResolveAgain(XSpaceManagerService.java:145)
    at com.android.server.am.ActivityStackSupervisorInjector.resolveXSpaceIntent(ActivityStackSupervisorInjector.java:68)
    at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:898)
    at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478)
    at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465)
    at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245)
            at android.os.Binder.execTransact(Binder.java:446)

2 个答案:

答案 0 :(得分:1)

只需检查您的onActivityResult()是否已被调用,因为您已使用Fragment。因此,您必须将活动的Activity结果传递给片段。

RegisterActivity中你必须写这个

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    fragment.onActivityResult(requestCode, resultCode, data);
}

然后您将在Fragment

中收到结果

希望它对你有所帮助。

答案 1 :(得分:0)

您是否尝试过禁用ProGuard?在build.gradle中将minifyEnabled设置为false并查看是否有帮助,您的配置可能已过期或不正确。

此外,您还可以检查您的设备是否运行了9.6.1+版本的Google Play服务。